import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
public class MyFrame extends JFrame {
static MainWindow mw;
public static void main(String[] args) throws UnsupportedLookAndFeelException,
ClassNotFoundException, InstantiationException, IllegalAccessException {
//Set the system look & feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
mw = new MainWindow();
}
});
}
}
class MainWindow extends JFrame {
public MainWindow() {
// I didn't use the setDefaultCloseOperation because I'd just be using
// the HIDE_ON_CLOSE value anyway
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
String[] ds = {"Cancel", "No", "Yes"};
int response = JOptionPane.showOptionDialog(null,
"You sure you wanna exit?",
"", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, ds, null);
if (response == 0) {
// The window closes anyway so I have to open a new version
// of the same type of window
new MainWindow();
} else if (response == 1) {
// The window closes anyway so I have to open a new version
// of the same type of window
new MainWindow();
} else if (response == 2) {
System.exit(0);
}
}
});
setSize(500, 400);
setVisible(true);
}
}
I can make due with this if I must but it looks really bad when you click "No" and it closes and then re-opens the frame.

New Topic/Question
Reply




MultiQuote






|