-1

Here's an ActionPerformed code for a logout button :

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
    JOptionPane jop = new JOptionPane();
    int option = jop.showConfirmDialog(null, "Voulez-vous vraiment vous déconnecter?", "Déconnexion", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
    if(option == JOptionPane.OK_OPTION){
        this.dispose();
        Connexion connexion = new Connexion();
        connexion.setVisible(true);
    }           
}    

Once I click right on the button, the application stops running How can I handle this?

Here's the rest of code for that button

jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sinpec/deco.png"))); 
jButton5.setBorderPainted(false);
jButton5.setContentAreaFilled(false);
jButton5.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/sinpec/deco1.png"))); // NOI18N
jButton5.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton5ActionPerformed(evt);
    }
});
jPanel1.add(jButton5);
jButton5.setBounds(70, 0, 50, 50);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Motie Khyaoui
  • 31
  • 1
  • 6
  • 1) The best formatting for blocks of code is had by selecting the code then clicking the `{}` button above the message posting/editing form. 2) Java GUIs have to work on different OS', screen size, screen resolution etc. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Apr 25 '15 at 00:22
  • @AndrewThompson I'm not sure about `connexion`, but he is probably executing the code from a JFrame and so `this.dispose()` causes the app to close. – Steffen Apr 25 '15 at 00:28
  • For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). – Andrew Thompson Apr 25 '15 at 00:33
  • @Veluria Good point. I missed that first line.. – Andrew Thompson Apr 25 '15 at 00:34

1 Answers1

0
    this.dispose();
    Connexion connexion = new Connexion();
    connexion.setVisible(true);

Change the order?

    Connexion connexion = new Connexion();
    connexion.setVisible(true);
    this.dispose();
camickr
  • 321,443
  • 19
  • 166
  • 288
  • I even tried to put what's inside the if block on comment but it doesn't solve the problem, the app still have the same problem once i click the logout button So it seems like the problem is really coming from the showConfirmDialog .... I don't understand – Motie Khyaoui Apr 25 '15 at 01:13
  • 1
    Me either and since you have posted a MCVE/SSCE we can't help. – camickr Apr 25 '15 at 03:06