0% found this document useful (0 votes)
16 views

ch15 Java Graphics SMS

The Graphics class provides methods for drawing various shapes and text to a canvas. It includes over 20 methods for drawing lines, arcs, ovals, polygons, rectangles, rounded rectangles, and strings. Methods like drawLine() and drawRect() draw hollow shapes while fillOval() and fillPolygon() draw solid, filled shapes. The class also offers methods for setting properties like color, font, and retrieving font metrics.

Uploaded by

RUDRAKSHI SAWANT
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

ch15 Java Graphics SMS

The Graphics class provides methods for drawing various shapes and text to a canvas. It includes over 20 methods for drawing lines, arcs, ovals, polygons, rectangles, rounded rectangles, and strings. Methods like drawLine() and drawRect() draw hollow shapes while fillOval() and fillPolygon() draw solid, filled shapes. The class also offers methods for setting properties like color, font, and retrieving font metrics.

Uploaded by

RUDRAKSHI SAWANT
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Chapter 15

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

You might also like