I have a swing JFrame and in a some place of the code i need to display a JOptionPane for the user to select: if yes - I need ht JFrame to run again and exit the existing one if no - this is solved I just need to exit.
here is a JFrame code:
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrame frame = new MainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
and here is the JOptionPane code which i created:
int ok = JOptionPane.showConfirmDialog(null, "would you like to enable USB in your device?", "USB", JOptionPane.YES_NO_OPTION);
if (ok==JOptionPane.YES_OPTION){
Thread t = new Thread(){
public void run(){
String[] args = { };
MainFrame f = new MainFrame();
f.main(args);
}
}.start();
}
else if(ok==JOptionPane.NO_OPTION){
System.exit(ok);
}
I created the thread and it is opening another JFrame but not closing the existing one!
Thanks for any help :)