Skip to main content
gamedev.net
๐Ÿ”’ Locked

[java] Calling methods from paintComponent()

Started by FiveFootFreak Dec 9, 2004 at 11:11 AM 1 replies 850+ views
Original Post
FiveFootFreak
FiveFootFreak
Hi there, anyone know why calling methods from "paintComponent" and passing the graphics context as argument doesn't work? Like this:

public void paintComponent(Graphics g){
        Graphics2D g2 = (Graphics2D)g;

        someObject.paintYourself(g2);        
}
The drawing code in "someObject.paintYourself" doesn't work. But it works if I put the code directly into paintComponent. Is the use of g2 only allowed inside the "paintComponent" method? But how can Java tell, that I'm in some other method and just passed g2 as argument?
FiveFootFreak
FiveFootFreak
Okay, nevermind... this works, the error was somewhere else in my code.

Always make sure the radius is greater than zero before trying to draw circles... :\

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.