I've recently started learning how to use Swing and graphics in Java and have come across two different approaches for designing a GUI.
1) To have the program's main method in an instatiation of the JFrame class.
2) To have a class which calls SwingUtilities.invokeLater() at the end of the main method to delay the thread that deals with graphics until after the initialisation of the main method.
e.g. 1.
class program extends JFrame {
public static void main(String[] args) {....}
}
e.g. 2.
class program implements Runnable {
public static void main() {
program p = new program();
SwingUtilities.invokeLater(p);
}
public void run() { ... }
}
How important is it to make the program thread safe as in approach 2? Also, what are the advantages and disadvantages of each approach? i.e. When would you use one approach over the other? etc.