Essay about Graphics Notes

Submitted By Sarnyak
Words: 458
Pages: 2

-

Graphics

▪ The Console class can be used to draw graphics such as lines, boxes, and other shapes. ▪ Graphics on screen consists of a tiny number of dots (pixels) (0, 0)

Starting
Point

▪ For example, if the center of a circle is (150, 100) it would be over to the right 150 pixel positions then down 100 pixel positions

Colour ▪ Use the setColor method in the Console class ▪ For example: c = new Console (); c.setColor (Color.green); //the color of the drawing //will be green ▪ Use setColor again for multiple colors ▪ Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow Width and Height c.getWidth() will give you the width of the console c.getHeight() will give you the height of the console

Take note of the 10 different shapes we can draw using Java

To Draw Lines: 1)drawLine (int x1, int y1, int x2, int y2) ▪ (x1, y1) is the starting point and (x2, y2) is the ending point Example: c.drawLine (100, 240, 500, 240)

To Draw Rectangles 2) drawRect (int x, int y, int width, int height) ▪ (x,y) is the location of the upper-left corner of box Example: c.drawRect (600, 10, 20, 30)

To Draw Ovals 3) drawOval (int x, int y, int width, int height) ▪ The oval is inscribed in a rectangle ▪ Upper left of rectangle is (x, y)

Example: c.drawOval (c.getWidth ()/2, c.getHeight()/2, 25, 40)

To Draw Coloured text
4) drawString (String message, int x, int y) ▪ To draw coloured text in any location on the screen ▪ Message is the string to be drawn ▪ (x, y) is the location of the lower-left corner of text

Example: c.drawString (“WOW”, c.getWidth()/2,…