1
I’m new to desktop programming, well, I’m making a program in java using swing and sqlite database, I’ve already made some things work, but after login the jframe that should open a single view opens twice, someone knows how to fix it?
Follow the pattern
private void entrar() {
String sql = "select * from login where usuario = ? and senha = ?";
try {
conn = conexao.ConnectionDB();
pst = conn.prepareStatement(sql);
pst.setString(1, nomeUser.getText());
pst.setString(2, senhaUser.getText());
rs = pst.executeQuery();
if (rs.next()) {
new TelaPrincipal().setVisible(true);
this.dispose();
} else {
JOptionPane.showMessageDialog(null, "Login inexistente");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
In its Telaprincipal class, it has main?
– user28595
No, my main is on the login screen.
– Aminadabe Silva
Apparently in the code you added in the question there are no problems, check in your Telaprincipal constructor if there is no call
setVisible(true)
. The problem does not seem to be in the question code.– user28595
I’ll hunt here, and give an answer
– Aminadabe Silva