/* related posts with thumb nails */

Graphics Class Methods:

The Graphics class several built-in methods to draw text and graphics on applets. The Graphics class is found in java.awt package. The paint() method takes  Graphics class object as argument. It plays two different, but related, roles. First, it is the graphics context. The graphics context is information that will affect drawing operations. This includes the background and foreground colors, the font, and the location and dimensions of the clipping rectangle (the region of a component on which graphics can be drawn). Second, the Graphics class provides methods for drawing simple geometric shapes, text, and images to the graphics destination. It supports coordinate system.

Following are some of the important methods found in Graphics class.  


drawText(String s, int x, int y)
Prints the string ‘s’ at (x,y).
setColor(Color c)
Set the current pen color to draw line, circle and etc.
getColor()
Returns the current Color
drawLine(int x1, int y1, int x2, int y2)
Draws a line between the points (x1,y1) and (x2,y2)
drawRect (int x, int y, int width, int height),
fillRect (int x, int y, int width, int height)
Draws (fills) a rectangle, (x,y) are the coordinates of the top left corner, the bottom right corner will be at (x+width,y+height)
drawOval (int x, int y, int width, int height),
fillOval (intx, int y, int width, int height)
Draws (fills) an oval bounded by the rectangle specified by these parameters.
draw3DRect (), fill3DRect()
Draws (fills) a rectangle with shaded sides that provide a 3-D appearance.
drawRoundRect(), fillRoundRect()
Draws (fills) a rectangle with rounded corners.
drawArc()
An arc is formed by drawing an oval between a start angle and a finish angle. 
drawPolygon (int[] x, int[] y, int n)
Draws lines connecting the points given by the x and y arrays. Connects the last point to the first if they are not already the same point. 
setFont(Font f)
Sets the font


Related Topics:

0 comments:

Post a Comment