ch15 Java Graphics SMS
ch15 Java Graphics SMS
Graphics
The Graphics Class
• Java’s Graphics class includes methods for drawing many different types of
shapes, from simple lines to polygons to text in a variety of fonts.
Method Description
clearRect() Erases a rectangular area of the canvas
copyArea() Copies a rectangle area of the canvas to another area
drawArc() Draws a hollow arc
drawLine(x1,y1, x2,y2) Draws a straight line
drawOval(x,y,width,height) Draws a hollow oval, (x,y: top left corner of imaginary rectangle)
drawPolygon() Draws a hollow polygon
drawRect(x,y,width,height) Draws a hollow rectangle, (x,y: coordinates of top left corner)
drawRoundRect(x,y,w,h,aw,ah) Draws a hollow rectangle with rounded corners, angle width & height
drawString(string,column,row) Displays a text string at column, row
fillArc() Draws a filled arc
Graphics Class methods……
Method Description
fillOval() Draws a filled oval
fillPolygon() Draws a filled polygon
fillRect(x,y,width,height) Draws a filled rectangle
fillRoundRect(x,y,w,h,aw,ah) Draws a filled rectangle with rounded corners
getColor() Retrieves the current drawing colour
getFont() Retrieves the currently used font
getFontMetrics() Retrieves information about the current font
setColor(Color.colorname) Sets the drawing colour
setFont() Sets the font
drawPolygon(xPoints, yPoints, nPoints);
xPoints = An array of integers containing x coordinates
yPoints = An array of integers containing y coordinates
nPoints = An integer for the total number of points