0
I am trying to check the login screen, to know if there is already the configuration file where the access information is set. If it doesn’t exist, it was supposed to give dispose
on the login screen and open the configuration screen.
For some reason, the dispose
does not work when I put the method on startup, thus:
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 could I be doing wrong?
That’s what I figured @diegofm... Initially the check was before the login screen opened, but for some reason, the design I created, is totally different, as for example the Abels that when they do not disappear, they get totally different fonts.
– Wilian Silva
@Wiliansilva the ideal is to check this before giving
new
in class, so you reduce even the use of resources unnecessarily when not to open the screen.– user28595