Jframe opening repeatedly twice

Asked

Viewed 157 times

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?

  • No, my main is on the login screen.

  • 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.

  • I’ll hunt here, and give an answer

1 answer

1

Hello, I managed to solve the problem, actually it was a mistake of mine, it happens that I had put the event Keypressed and the actionPerformade with the way to enter, but somehow, even clicking with the mouse the Keypressed activated, basically removed the Keypressed and worked thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.