I'm sorry, I'm having an awful day and a really hard time figuring out why I can't paint the Car objects onto a JFrame OR its ContentPane. The JFrame appears, but no cars appear on it. Anything that can point me in the right direction? This is homework, so I don't want a spoon-fed solution, but maybe if you see something that I'm overlooking, it will help. As usual, thanks in advance!
Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
Joined: Aug 17, 2006
OK, sorry, I see now (finally!!!) that paint() was wiping the slate clean, so maybe I can take it from here. Thanks!
that paint() was wiping the slate clean, so maybe I can take it from here.
And the problem is that you can't control when Swing decides the frame needs to be repainted.
Read the section from the Swing tutorial on Custom Painting. Basically, custom painting is done by override the paintComponent() method of a JPanel or JComponent. That way when Swing decides the frame needs to be repainted, your custom component will repaint itself correctly.
You should never use the getGraphics() method to get a Graphics object. The Graphics object will be passed to you in the paintComponent() method.
Also, get rid of all the static methods and variables. That is the sign of a poorly designed program. Again the Swing tuturial has proper working examples.