# A First Look at Graphics with the ACM Libraries

The ACM libraries provide a simple way to write java programs with graphical outputs. ACM graphics programs can be thought of as functioning much like a felt board, where various shapes can be "stuck to the board". The ACM libraries come with many such shapes, each of which is represented by a class (whose name is shown in parentheses below):

• Rectangle (GRect)
• Oval (GOval)
• Line (GLine)
• Polygon (GPolygon)
• Arg (GArc)
• Rectangle with a 3D effect on its border (G3DRect)

Details on all of these objects, their constructors, methods, and more can be found in the ACM documentation.

Just as an example, the following program draws the following to the graphics window when run:

import acm.program.*;
import acm.graphics.*;
import java.awt.Color;  //this is needed to use the constant "Color.RED" below

public class SampleProgram extends GraphicsProgram {

public void run() {

//construct a rectangle whose upper left corner is at (0,0)
//and with width 50 and height 100; reference it with a variable
//named myRect and add it to the graphics window
GRect myRect = new GRect(0,0,50,100);

//construct an oval whose upper left corner is at (25,25)
//and with width 50 and height 100; reference it with a variable
//named myOval; set things so that when drawn on the screen
//its interior will be filled in and the entire oval will be red in color;
//and then add it to the graphics window.
GOval myOval = new GOval(25,25,50,100);
myOval.setFilled(true);
myOval.setColor(Color.RED);