3
In the code below, I want you to choose sim
the window closes and when choosing não
the window remains open.
private void formWindowClosing(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
int Confirm = JOptionPane.showConfirmDialog(null,"Encerrar?","sim ou nao", JOptionPane.YES_NO_OPTION);
if (Confirm == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "");
System.exit(0);
} else if (Confirm == JOptionPane.NO_OPTION){
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
There is no mistake, the problem is that when choosing sim
window closes. So far correct, but when choosing não
it closes the same way.
What a mistake you made in your attempt?
– Math
no error... the problem is that when choosing yes the window closes.. up to right... more when choosing not it closes in the best way..
– Netobass
Vlw guys more already worked akie.. OBG..
– Netobass
Netobass, you can publish the solution as a response below?
– brasofilo
if (JOptionPane.showConfirmDialog(null, "Encerrar?","sim ou nao", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
} else {
 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE)
}
– Netobass
as I do not have 10 points still akie on the forum so I can not define the answer yet..
– Netobass
@Netobass can. You don’t need points to leave an answer. Search below
Publique sua resposta
– Sergio