import java.awt.Color; import java.awt.Rectangle; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JComponent; import java.util.Random; /** A class to test the correctness of the ColorTriangle and ColorTriangleComponent classes. @author Jeff Smith @version final version for Assignment 5, CS 49J, Spring 2009, SJSU */ public class ColorTriangleTester extends JComponent { /** A private method to encapsulate all of the instructions needed to create a frame that are independent of a particular ColorTriangle */ private static JFrame makeFrame(int width, int height) { JFrame frame = new JFrame(); int frameWidth = width; int frameHeight = height; frame.setSize(frameWidth, frameHeight); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); return frame; } /** A method to test the correctness of the ColorTriangle and ColorTriangleComponent classes. @param args is ignored */ public static void main(String[] args) { JFrame frame1 = makeFrame(960, 640); ColorTriangleComponent ctc1 = new ColorTriangleComponent(); ctc1.addColorTriangle(new ColorTriangle(0,200,800,400,32,255)); ctc1.addColorTriangle(new ColorTriangle(0,0,100,200,8,255)); ctc1.addColorTriangle(new ColorTriangle(100,0,300,200,20,255)); ctc1.addColorTriangle(new ColorTriangle(400,0,400,200,64,255)); ctc1.addColorTriangle(new ColorTriangle(800,0,100,100,2,255)); ctc1.addColorTriangle(new ColorTriangle(800,110,100,100,-1,255)); frame1.add(ctc1); frame1.setVisible(true); JFrame frame2 = makeFrame(960, 640); Random r = new Random(2); ColorTriangleComponent ctc2 = new ColorTriangleComponent(); for (int i=0; i<5; i++) ctc2.addColorTriangle(new ColorTriangle( 150*i, 100*i, 50 + r.nextInt(100), 50 + r.nextInt(50), 4+r.nextInt(32), 127 + r.nextInt(256))); frame2.add(ctc2); frame2.setVisible(true); JFrame frame3 = makeFrame(960, 640); ColorTriangleComponent ctc3 = new ColorTriangleComponent(); ctc3.addColorTriangle(new ColorTriangle(0,0,100,200,8,191)); ctc3.addColorTriangle(new ColorTriangle(100,0,300,200,20,383)); ctc3.addColorTriangle(new ColorTriangle(400,0,400,200,64,511)); ctc3.addColorTriangle(new ColorTriangle(0,200,800,400,32,255)); frame3.add(ctc3); frame3.setVisible(true); } }