/** * MyArtWork * Inspired by a lab from Jeff Ondich * @author Dave Musicant * @version 3.0 5/1/03 * * This class opens a canvas window, fills it with a black * background, and draws a purple square in the center. */ import java.awt.*; public class MyArtWork { public static void main( String[] args ) { // Set up the canvas. int windowWidth = 500; int windowHeight = 500; int rectangleWidth = 50; int rectangleHeight = 50; Canvas canvas = new Canvas( "Not quite Picasso" ); canvas.setSize( windowWidth, windowHeight ); canvas.setVisible( true ); // Set the background color of the Canvas. // The Color class has class variables to indicate built-in // 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. canvas.fillBackground( Color.black ); // If you want to mix your own colors, create a new Color // object. The constuctor takes three parameters which are // ints between 0 and 255, representing the amount of red, // green, and blue in the color. So (0,0,0) means no color // (black), (255,0,255) means a shade of purple, and // (127,0.127) is darker purple, etc. Color darkPurple = new Color( 127, 0, 127 ); // Set the color of the pen. The "pen color" refers to the color // that will be used for all future drawing operations, until the // pen color is changed again. canvas.setInkColor( darkPurple ); // Draw a square. More specifically, draw a rectamgle whose top // left corner has coordinates (measured in pixels) // x = windowWidth/2 and y = windowHeight/2, and whose width // and height are specified by the variables rectangleWidth and // rectangleHeight. canvas.drawRectangle( windowWidth/2, windowHeight/2, rectangleWidth, rectangleHeight ); } }