I'm trying to check the login screen to see if the configuration file where the access information is already set exists. If it does not exist, it was supposed to give dispose
on the login screen and open the setup.
For some reason, dispose
does not work when I put the method on startup, like this:
public class ViewLogin extends javax.swing.JFrame {
public String login;
public String nomeDoUser;
public String usern;
public ViewLogin() {
initComponents();
verifyConfig(); <--
setIcon();
colorOverlay.setBackground(new Color(51, 51, 51, 155));
passField.requestFocus();
this.nomeDoUser = nomeDoUser;
this.usern = usern;
}
public void verifyConfig() {
File f = new File("config.ini");
if (!f.exists()) {
new ViewConfig().setVisible(true);
this.dispose();
}
}
However, if I put on a button, it works perfectly:
private void btnLoginMousePressed(java.awt.event.MouseEvent evt) {
File f = new File("config.ini");
if (!f.exists()) {
new ViewConfig().setVisible(true);
this.dispose();
} else {
UserDAO dao = new UserDAO();
if (dao.checkLogin(usrField.getText(), passField.getText())) {
new ViewHome(dao.nomeDoUser, dao.usern).setVisible(true);
this.dispose();
} else {
new ViewLoginError().setVisible(true);
}
}
}
What can I be doing wrong?