- Go to the class with the same name as the form.
-
Press the keyboard shortcut for “Generate”. It’s Ctrl+N on Mac OS X, Alt+Ins on Windows. Alternatively, from the menu, select menu Code → Generate.
-
Select “Form main()”.
Now the main method is written and inserted for you. It will look something like this:
public static void main(String[] args) {
JFrame frame = new JFrame("MyForm");
frame.setContentPane(new MyForm().mainPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}