This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I'm reading the Head First Java book and am having problems using the example regarding the paintComponent method (pg. 364 chapter 12). I've made a subclass of JPanel but cannot seem to call the paintComponent method. I've pasted my code below; any tips would be appreciated!
Don't hijack old postings. This posting is about "painting". Your question has nothing to do with painting.
Read the section from the Swing tutorial on Using Top Level Containers which will help explain the structure of a JFrame and its child components. The Swing tutorial is probably a better reference than Head First Java because it is more current.
In the first case you are replacing the content pane with your panel.
In the second case you are adding your panel to the content pane.
Effectively they are the same because you can still add components to the frame however you want.
Look at the examples in the Swing tutorial to see which approach is used most often.