aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Doubt in a program that deals with paintComponent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Doubt in a program that deals with paintComponent" Watch "Doubt in a program that deals with paintComponent" New topic
Author

Doubt in a program that deals with paintComponent

vamsi naki
Ranch Hand

Joined: May 18, 2011
Posts: 46
Hi,
I basically copied a program from a book and ran it .In the porgram a circle moves from one position to the other slowly .I have a doubt as to how the program is running ,I dont understand how or where the method paintComponent is being called in the program.


][/code]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
it is an overridden method of JPanel (or inherited method)

look into the source code to find out more
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
Shouldn’t is have protected access?

That method is called by the JVM is response to various events, eg the GUI becoming visible, coming to the front, being exposed by another object on screen, an invocation of repaint(). It might be worth reading the source of repaint(), too.
Caleb Kemper
Greenhorn

Joined: Feb 08, 2012
Posts: 27

You'll never explicitly call paintComponent(g), Java will.
The method repaint() instructs Java to call paintComponent(g) through a series of other calls. This is not explicit however, and is in no way guaranteed.
I recommend Googling about the hierarchy of calls that takes place when repaint() is called, and maybe follow through some painting tutorials.

Best,
Caleb
vamsi naki
Ranch Hand

Joined: May 18, 2011
Posts: 46
Hi ,
Thanks a lot for explaining Caleb Kemper,Campbell Ritchie and Michael Dunn .
Campbell Ritchie ,i couldnt quiet get this line ,do you mean that paintComponent should have protected access?
Campbell Ritchie wrote:Shouldn’t is have protected access?



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
Caleb Kemper wrote:You'll never explicitly call paintComponent(g), Java will. . . .
That is why you don’t want it to have public access. It has protected access so you can override it, but not public, because you don’t want it to be called from outside your class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in a program that deals with paintComponent