tags:

views:

63

answers:

4

I have seen the term several times, what does it mean?

+2  A: 

It's an object you can use to draw graphics primitives on a SWING/AWT program.

Example:

class JMyComponent extends JComponent
{
    @Override
    public void paint(Graphics g) {  
        // g contains graphics context
        g.fillOval(...);  // draw an oval on the component
        // more graphics primitives...
    }
}

There are similar contexts in pretty much every other UI framework. Java or Non-Java.

Pablo Santa Cruz
I would upvote but in Swing custom painting is done by overriding the paintComponent(...) method.
camickr
A: 

To do any drawing at all in Java, you need a graphics context. A graphics context is an object belonging to the class, java.awt.Graphics.

http://www.faqs.org/docs/javap/c6/s3.html

Evan Mulawski
A: 

The Graphics context is the Graphics object, which contains all the things needed to do drawing within Java

http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Graphics.html

In most AWT and Swing components, you can override the paint(Graphics g) method to implement your own drawing method. It passes in the Graphics context (the graphics object) for you to perform you drawing methods on.

Codemwnci
+3  A: 

"Context" is a generic name that many java developers use for classes that carry state information. So are bound to see a lot of different class names containing context.

Graphic context in desktop Java usually means java.awt.Graphics or java.awt.Graphics2D classes. They carry information about drawing properties: colors, line properties, clipping regions, etc..

Peter Knego