import javabook.*; import java.awt.*; /** * DrawingLab2 * Inspired by a lab from Jeff Ondich * @author Dave Musicant * @version 2.0 12/20/01 * * 0. Try it. * * 1. The "polygonX[3] = 400" notation is something you will meet soon * (polygonX is called an "array"). For this program, all you need to * know is that polygonX[0] and polygonY[0] are the (x,y) coordinates * of the first corner of the polygon, polygonX[1] and polygonY[1] are * the coordinates of the second corner, etc. * * 2. Identify which corner of the polygon has which coordinates as listed * in the source code. * * 3. Try to redesign the polygon to be a triangle or a rectangle. * * 4. Change "drawPolygon" to "fillPolygon" and try the program again. */ class DrawingLab2 extends MainWindow { // Data values final private int windowWidth = 600; final private int windowHeight = 600; public DrawingLab2() { setVisible(true); toFront(); setSize(windowWidth,windowHeight); setBackground(Color.white); repaint(); } public void paint(Graphics graphics) { int[] polygonX = new int[5]; int[] polygonY = new int[5]; polygonX[0] = 200; polygonY[0] = 100; polygonX[1] = 400; polygonY[1] = 100; polygonX[2] = 500; polygonY[2] = 200; polygonX[3] = 400; polygonY[3] = 300; polygonX[4] = 200; polygonY[4] = 200; // Draw. graphics.setColor(Color.red); graphics.drawPolygon(polygonX,polygonY,5); } public static void main(String[] args) { DrawingLab2 dw = new DrawingLab2(); } }