![]() |
![]() |
Intro. to Graphics class | |
Drawing - Lines , Rectangles | |
Drawing - Circles and Ellipse | |
Drawing - Arcs | |
Drawing - Polygons | |
Drawing - Bar Charts |
Java Programs | |
Java Keywords Dictionary | |
Java Interview Questions |
Graphics can be drawn with the help of java applet.
Java applets are written to draw lines,figures of different shapes,images and text in different styles even with the colours in display.
Every applet has it's own area of the screen known as canvas, where it creates the display in the area specified the size of applet's space is decided by the attributes of < applet ..> tag
A java applet draws graphical image inside it's space using the coordinate system as shown in above fig.
Java's coordinate system has the origin (0,0) in the upper-left corner, positive x values are to right and positive y values are to the bottom.
These coordinate values of x and y axis are in Pixels.
The graphics class of java includes methods for drawing different types of shapes,from line to polygons to text in a variety of fonts.
In applet, the paint() method and a Graphics class object is used to display text. To draw shapes on applet graphics class methods are used which of the have arguments representing ends points,corners in the coordinate system.
Method Name | Description |
---|---|
drawRect() | This method draws a hollow rectangle |
fillRect() | This method draws a filled rectangle |
drawRoundRect() | This method draws a hollow rectangle with rounded corners. |
fillRoundRect() | This method draws a filled rectangle with rounded corners. |
drawPolygon() | This method draws a hollow polygon. |
fillPolygon() | This method draws a filled polygon. |
drawOval() | This method draws a hollow oval. |
fillOval() | This method draws a filled oval. |
drawArc() | This method draws a hollow arc. |
fillArc() | This method draws a filled arc. |
drawLine() | This method draws a straight line. |
drawString() | This method displays a string text. |
Method Name | Description |
---|---|
copyArea() | This method copies a rectangular area of the canvas to another area. |
clearRect() | This method erases a rectangular are of the canvas. |
getColor() | It retrives the current drawing colour |
getFont() | It retrives the currently used font. |
getFontMetrics() | It retrives information about the current font. |
setColor() | Sets the drawing color. |
setFont() | Sets font |