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?

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top