• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in a program that deals with paintComponent

 
vamsi naki
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is an overridden method of JPanel (or inherited method)

look into the source code to find out more
 
Campbell Ritchie
Sheriff
Pie
Posts: 49812
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49812
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic