This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Game Development and the fly likes My paint method is moody today Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "My paint method is moody today" Watch "My paint method is moody today" New topic
Author

My paint method is moody today

Wes McClintock
Greenhorn

Joined: Jul 19, 2011
Posts: 25
I have literally no idea whats wrong here. The applet launches and runs fine, but doesn't display anything.

and here i declare my stuff in init()


and i have this stuff declared as well


Im new to java, so if having another "fix my code" thread bugs you Im sorry. your help is really appreciated.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If you override the paint() method with something simpler, like just colouring everything green, does that work?
Wes McClintock
Greenhorn

Joined: Jul 19, 2011
Posts: 25
Paul Clapham wrote:If you override the paint() method with something simpler, like just colouring everything green, does that work?

no, I tried removing anything involving images and just drew a a line, but it didn't work. I find this extremely weird because the code is taken almost line for line from my pong program, and than runs fine.
Spencer Zelle
Greenhorn

Joined: Jul 24, 2011
Posts: 2

Try making a call to the super classes's paint method. Something like this.


Also depending on what component your using to draw (if your using Swing or AWT) it is usually better to override paintComponent(). The reason for this is AWT uses paint() which handles other things like painting the components border, and the components "children", not just painting the component itself. Swing however, uses three paint methods paintComponent(), paintBorder(), and paintChildren() to do all the painting. So if your using a Swing component overriding paintComponent() means your not messing with the component's border and child painting.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: My paint method is moody today
 
Similar Threads
Image+Button+applet
paint(Graphics gr) returns nullpointerexception ?
jpanel paint image using method like jpanel1.paint
back_buffer ?
Double Buffering Problem