在java中显示确认对话框

时间:2015-04-25 00:20:36

标签: java swing events awt jbutton

这是一个用于注销按钮的ActionPerformed代码:

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);
    }           
}    

点击按钮后,应用程序停止运行 我怎么处理这个?

以下是该按钮的其余代码

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);

1 个答案:

答案 0 :(得分:0)

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

更改订单?

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