By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,737 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,737 IT Pros & Developers. It's quick & easy.

paintComponent

P: n/a
The following code segment is the beginning of a user-defined
paintComponent method:

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

}

My questions are:

What does the super.paintComponent(g) do?

Where does the input argument, Graphics g come from? (i.e. How is it
passed to the paintComponent method?)

What does the Graphics g object do? (i.e. What information does it
store and what methods does it have?)

Why does the Graphics g object need to be cast to one of type
Graphics2D?
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
your on a learning curve i see

a) the super.paintComponent(g); method allows your specialized class to
utilize functionality in the origional class. unless you want to
completely override that behaviour, or duplicate it, this method call
allows you to utilize it and then add your own specialized behaviour for
your sub class.

b) the input argument "g" is created by the rendering device, say screen
or printer, it's created by the class objects of the Java2D Api that
will be making use of your specialized class. you do not need to worry
about it's contents. in effect, it is pretty much an object that carries
context information for the graphical object your are using.

c) Java2D is pretty much a standard as issued by Sun. you cast a
Graphics object to a Graphics2D object when you are using Java2D
methods. this allow you to utilize the additional methods associated
with the Graphics2D object without having to cast each time. in theory,
it is possible for a none Graphics2D object to reach your code that is
anticipating that class and this could cause problems, but unless you
are using a non Java2D class library, this is typically not something to
worry about.

- perry

Rupam wrote:
The following code segment is the beginning of a user-defined
paintComponent method:

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

}

My questions are:

What does the super.paintComponent(g) do?

Where does the input argument, Graphics g come from? (i.e. How is it
passed to the paintComponent method?)

What does the Graphics g object do? (i.e. What information does it
store and what methods does it have?)

Why does the Graphics g object need to be cast to one of type
Graphics2D?


Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.