• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in a program that deals with paintComponent

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is an overridden method of JPanel (or inherited method)

look into the source code to find out more
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 27
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic