You are on page 1of 2

Java Graphics

- Java coordinate system


- (x,y) pairs, x - horizontal axis, y - vertical axis
- Upper left corner is (0,0)
- Coordinates measured in pixels

- Standard class is provided


- java.awt.Graphics
- Use the class through: Graphics context
- Graphics context: an important instantiated object. It is an instance of java.awt.graphics
class and refer to an area of screen.

- Graphics context: provides methods for all of the drawing operations on its area. It also
holds "contextual" information about such things as the drawing area's clipping region, painting
color, transfer mode, and text font.

- Most often the graphics context is obtained from the Java window manager as a result of a
painting request. This context is passed to your component's paint() or update() method. We
have a example later to show how to use it
Java Graphics
- About class: java.awt.graphics
- Class Hierarchy
java.lang.Object
|
+----java.awt.Graphics

- Include into your code through: import java.awt.graphics


- Methods examples:
- Graphics() //constructor
- setFont(Font) //set current font
- setColor() //set current color
- getFont() //get current Font
- getColor() //get current color
- drawRect(int,int,int,int) //draw the outline of specified rectangle with current color
- fillRect() //fill the specified rectangle with current color

You might also like