Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing Components and Graphics Objects

 
Landon Blake
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to learn a little about Swing before I make my first attempt at programming a GUI. I had a couple of questions:
When is a graphics object passed to a Swing Component for painting?
Does this only happen with custom components, or all components?
What does the graphics object help the compnent do?
How is it involved in the painting process?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Graphics object is passed to the paintComponent() method of any component that needs to be painted. AFAIK, this happens with all components. The Graphics class provides functions that allow you to paint on a window or other component. These methods include drawLine(), drawRect(), and many others. For more details, you should look at the API documentation for the Graphics class. It lists all the methods that are available for your use. In fact, you should bookmark the index for the API docs for the version of the Java SDK that you are using and learn how to navigate it. These documents provide most of the information you need about any class in the API.
HTH
Layne
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
[ February 27, 2004: Message edited by: Dirk Schreckmann ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic