what is a graphics context (In Java)?
I have seen the term sev开发者_开发百科eral times, what does it mean?
"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..
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.
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.
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
Graphical context is the logical output device. This could be for example a computer screen.
The Graphics class in Java allows interacting with the Graphics context.
For more information: https://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html
精彩评论