Estou fazendo um Login e quando coloco this.dispose(); dá a mensagem “The method dispose() is undefined for the type new SelectionAdapter(){}”.
como posso fazer para fechar esta janela sem fechar o programa todo?
deixo aqui o codigo:
public class MenuLogin {
protected Shell shlSge;
private Text user;
private Text pass;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
MenuLogin window = new MenuLogin();
window.open();
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
* @throws IOException
*/
public void open() throws IOException {
Display display = Display.getDefault();
createContents();
shlSge.open();
shlSge.layout();
while (!shlSge.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() throws java.io.IOException{
shlSge = new Shell();
shlSge.setImage(ResourceManager.getImage("Logo25x25.jpg"));
shlSge.setSize(450, 300);
shlSge.setText("SGE");
Label lblUtilizador = new Label(shlSge, SWT.NONE);
lblUtilizador.setBounds(136, 75, 55, 15);
lblUtilizador.setText("Utilizador");
Label lblPassword = new Label(shlSge, SWT.NONE);
lblPassword.setBounds(136, 111, 55, 15);
lblPassword.setText("Password");
final Label lblEUser = new Label(shlSge, SWT.NONE);
lblEUser.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
lblEUser.setBounds(298, 69, 100, 15);
final Label lblEPass = new Label(shlSge, SWT.NONE);
lblEPass.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
lblEPass.setBounds(298, 108, 100, 15);
final Label lblELogin = new Label(shlSge, SWT.NONE);
lblELogin.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
lblELogin.setBounds(141, 215, 151, 15);
user = new Text(shlSge, SWT.BORDER);
user.setBounds(216, 69, 76, 21);
pass = new Text(shlSge, SWT.PASSWORD | SWT.BORDER);
pass.setBounds(216, 108, 76, 21);
Button btnOK = new Button(shlSge, SWT.NONE);
btnOK.setBounds(136, 163, 75, 25);
btnOK.setImage(SWTResourceManager.getImage("Entrar.png"));
btnOK.setText("Entrar");
btnOK.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
lblEUser.setText("");
lblEPass.setText("");
lblELogin.setText("");
String nutil = user.getText();
String ppass = pass.getText();
Shell shell = null;
if(nutil==""){
lblEUser.setText("Insira o username");
}
if(ppass==""){
lblEPass.setText("Insira a password");
}
else
{
try{
Scanner ler= new Scanner(new File("utilizadores.txt"));
String[] linha;
while(ler.hasNextLine()){
linha = ler.nextLine().split(":");
String NomeNoFicheiro=linha[0];
String PasswordNoFicheiro=linha[1];
String NomeUtilizadorNoFicheiro=linha[2];
String Cat=linha[3];
if(nutil.equals(NomeNoFicheiro)&&ppass.equals(PasswordNoFicheiro))//verifica se o username coicide com a password
{
switch (Cat){
case "D": //categoria alunos
// Menus CMenuAlunos=new Menus();
// CMenuAlunos.MenuAluno(NomeUtilizadorNoFicheiro);
System.out.println(“Falta acabar”);
break;
case "C"://categoria profs
MenuDocentes MDocen= new MenuDocentes();
MDocen.open();
break;
case "B"://categoria profs responsaveis
MenuDocentesResp MDocenR= new MenuDocentesResp();
MDocenR.open();
this.dispose(); // [b]É esse que dá erro[/b]
break;
case "A"://categoria Funcionarios
System.out.println("Falta acabar");
break;
default:
System.out.println("Falta acabar");
break;
}
}
else
lblELogin.setText("O utilizador não existe");
}
ler.close();
}
catch(FileNotFoundException e1){
System.out.println(e1.getMessage());
}
}
}
});
Button btnSair = new Button(shlSge, SWT.NONE);
btnSair.setBounds(217, 163, 75, 25);
btnSair.setImage(SWTResourceManager.getImage("Sair.png"));
btnSair.setText("Sair");
btnSair.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
System.exit(0);
}
});
Label lblLogo = new Label(shlSge, SWT.NONE);
lblLogo.setAlignment(SWT.CENTER);
lblLogo.setImage(ResourceManager.getImage("Logo100x100.jpg"));
lblLogo.setBounds(10, 69, 100, 100);
}
}
obgdo