Written by Chris Piech
The point of this program is to show you a graphics program with each of the key shapes. We should draw two rectangles (one blue and one yellow), draw one red oval, with a black non-filled rectangle in the same location. In the center of the screen we write "Programming is Awesome." Here is what our program looks like:
Here is the corresponding code:
import acm.graphics.*;
import acm.program.*;
import java.awt.*;
public class ProgrammingAwesome extends GraphicsProgram {
// draws the screen in the picture above
public void run() {
// half the height of the screen.
double centerY = getHeight()/2;
// make and add a blue square
GRect blueSquare = new GRect(80, 80); // width and height are 80
blueSquare.setColor(Color.BLUE); // make the square blue
blueSquare.setFilled(true); // fill the square
add(blueSquare, 70, 70); // add the square to the screen
// add a long yellow rectangle
GRect yellowRect = new GRect(40, 360);
yellowRect.setColor(Color.YELLOW);
yellowRect.setFilled(true);
add(yellowRect, 600, 10);
// make and add a red oval
GOval redOval = new GOval(120, centerY); // width and height
redOval.setColor(Color.RED);
redOval.setFilled(true);
add(redOval, 200, 180); // add to location (200, 180)
// make and add a rectangle which fits around the red oval
GRect circleOutline = new GRect(120, centerY);
add(circleOutline, 200, 180);
// add a piece of text
GLabel label = new GLabel("Programming is Awesome!");
label.setFont("Courier-52");
add(label, 10, centerY);
// this object is never added
GRect dudeWheresMyRect = new GRect(600, 600);
dudeWheresMyRect.setFilled(true);
// since it is not added, we will never see it...
}
}