When making an application using Swing, I\'ve seen people do one of the two things to create a JFrame. Which is a better approach and why?
I\'m a beginner at Java an
Prefer composition over inheritance.
The 2nd example uses inheritance, but for no good reason, since it does not change the functionality of JFrame.
As an aside, if those are examples of code you are seeing, find a new source1 supplementary. Even in the few code lines shown, each does highly questionable things. E.G.
getContentPane().setBackground(Color.WHITE);
getContentPane().setLayout(null);
setSize(800, 600);
getContentPane()) has not been necessary since Java 1.5null layout, which will break in more ways I can count or describe.pack();JFrame guiFrame = new JFrame();
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guiFrame.setTitle("Example GUI");
guiFrame.setSize(300,250);
JFrame guiFrame = new JFrame("Example GUI");guiFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);