/*------------------------------------------------------------------------------------*/ /* Applet: ShapesAndColors */ /* Author: Jamal El-Mokadem */ /* Date: 11/13/00 */ /* Description: This applet that allows the user to draw shapes, and specify their */ /* colors. It also presents the user with the ability to stack shapes on top of each */ /* other, and clear all drawn shapes with a push of a button. */ /* The applet, which I called the "ShapesAndColors", consists of a control panel, */ /* and a drawing area. The Control Panel is located at the south (bottom) end of */ /* the applet. It contains three choice controls (pull-down menus)-Shape, Color, */ /* Style- and one "Reset" button: */ /* - The Shape Control allows the user to choose among three shapes to draw: */ /* Line, Rectangle, and Ellipse. */ /* - The Color Control allows the user to determine the chosen shape's color. */ /* The available colors are Green, Blue and Yellow. */ /* - The Style Control offers the user the ability to draw a Hollow, or Filled */ /* shape. */ /* - The Reset Button presents the user with the ability to clear all drawn */ /* shapes. */ /* The Drawing Area forms the rest of the applet. It has a light gray background, */ /* same as the Control Panel. The user can draw and stack shapes in this area. */ /*------------------------------------------------------------------------------------*/ /*--------------------------------------*/ /* Import the following class libraries */ /* needed to implement the applet */ /*--------------------------------------*/ import java.applet.*; import java.awt.*; /** *This is the main class that creates two instances *of the whiteBoard class and the controlStrip class *relatively */ public class ShapesAndColors extends Applet{ /*--------------------------------*/ /** * This will initialize the class. * It will will create and add instances of the whiteBoard and controlStrip classes */ /*--------------------------------*/ public void init() { // creates the layout setLayout(new BorderLayout()); whiteBoard board = new whiteBoard ();/*-----------------------------------*/ add("Center", board); /* creates and adds an instance */ add("South",new controlStrip(board));/* of the whiteBoard and controlStrip*/ } /* classes */ /*-----------------------------------*/ /*----------------------*/ /**class starting point * It will create a frame and add an instance of ShapesAndColors to it */ /*----------------------*/ public static void main(String args[]) { // Creates a new frame Frame f = new Frame("ShapesAndColors"); // and a new instance of the class ShapesAndColors board = new ShapesAndColors (); //Initialize the newly created object board.init(); //and start it board.start(); //Position the object within the frame f.add("Center", board); //Set its size f.setSize(500, 500); //And show it... f.show(); } }