Question

I've got multiple JFrames and each of them has a 'main'. The one that opens when I click 'Run' is the first JFrame I created. How can I change it so that a different JFrame I made opens up?

Was it helpful?

Solution

You shouldn't have more public static void main(String[] argv) methods in your application, and as a matter of fact, only one JFrame is typically used. The others are done with JDialog, which does some nice things for you, such as disabling the main window when active.

The main method creates the main frame, and others are then opened based on some events in this frame.

You open a dialog window (MyDialog extends JDialog) somewhat like this:

JDialog dlg = new MyDialog(mainFrame);
dlg.setVisible(true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top