Class DrawPad

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----java.applet.Applet
                                   |
                                   +----DrawPad

public class DrawPad
extends Applet
implements MouseListener, MouseMotionListener, ItemListener, ActionListener
A Java applet which implements a drawing pad. It allows the user to create several different shapes, including:

The user can specify which color these shapes are made in, as well as whether they are filled or hollow.

Version:
1.0 (Nov. 2000)
Author:
Hans Wild
See Also:
Applet

Variable Index

 o clear
 o colors
 o filled
 o instructions
 o shapes

Constructor Index

 o DrawPad()

Method Index

 o actionPerformed(ActionEvent)
Clears drawing area by repainting window
 o changeLastPoint(int, int)
Updates last point x and y values with new values
 o init()
Initialization routine for the DrawPad class.
 o itemStateChanged(ItemEvent)
Updates current color, shape, or fill values based on which control was changed.
 o mouseClicked(MouseEvent)
Records the point where the mouse is clicked during the creation of a triangle.
 o mouseDragged(MouseEvent)
Records current point.
 o mouseEnter(MouseEvent)
Dummy event inserted for MouseListener interface
 o mouseEntered(MouseEvent)
Dummy event inserted for MouseListener interface
 o mouseExited(MouseEvent)
Dummy event inserted for MouseListener interface
 o mouseMoved(MouseEvent)
Creates rubberbanding effect for creation of triangle.
 o mousePressed(MouseEvent)
Records the point where the mouse is pressed to be used as an origin point for the shape being drawn.
 o mouseReleased(MouseEvent)
Records point where mouse button is released and draws appropriate shape, filling if needed.
 o updateInstructions()
Updates drawing instructions in window based on what shape is selected in the choice box.

Variables

 o colors
 public Choice colors
 o shapes
 public Choice shapes
 o filled
 public Checkbox filled
 o instructions
 public Label instructions
 o clear
 public Button clear

Constructors

 o DrawPad
 public DrawPad()

Methods

 o init
 public void init()
Initialization routine for the DrawPad class. Initializes variables, creates controls and also creates three panels to arrange controls on the screen.

Overrides:
init in class Applet
 o mouseEntered
 public void mouseEntered(MouseEvent e)
Dummy event inserted for MouseListener interface

Parameters:
e - MouseEvent object
 o mousePressed
 public void mousePressed(MouseEvent e)
Records the point where the mouse is pressed to be used as an origin point for the shape being drawn.

Parameters:
e - MouseEvent object, used to get point at mouse location
 o mouseClicked
 public void mouseClicked(MouseEvent e)
Records the point where the mouse is clicked during the creation of a triangle. If it is the second or third point, a line is drawn between the points already set. If it is the third point, the triangle is filled if needed, and the arrary of points is reinitialized.

Parameters:
e - MouseEvent object, used to get point at mouse location
 o mouseExited
 public void mouseExited(MouseEvent e)
Dummy event inserted for MouseListener interface

Parameters:
e - MouseEvent object
 o mouseReleased
 public void mouseReleased(MouseEvent e)
Records point where mouse button is released and draws appropriate shape, filling if needed.

Parameters:
e - MouseEvent object, used to get point at mouse location
 o mouseEnter
 public void mouseEnter(MouseEvent e)
Dummy event inserted for MouseListener interface

Parameters:
e - MouseEvent object
 o mouseDragged
 public void mouseDragged(MouseEvent e)
Records current point. In the case of a line, a line is drawn between the last point and the current point. The changeLastPoint() function is then called to set the last point to the current point.

In the case of a rectangle or oval, a temporary shape is created, and the previous temporary shape is erased. This gives a "rubberbanding" effect toshape creation.

Parameters:
e - MouseEvent object, used to get point at mouse location
See Also:
changeLastPoint
 o mouseMoved
 public void mouseMoved(MouseEvent e)
Creates rubberbanding effect for creation of triangle. This effect is created by drawing a temporary line from the previous anchored point of the triangle to the current point. The previous temporary line is erased.

Parameters:
e - MouseEvent object, used to get point at mouse location
 o updateInstructions
 protected void updateInstructions()
Updates drawing instructions in window based on what shape is selected in the choice box.

See Also:
itemStateChanged
 o changeLastPoint
 protected void changeLastPoint(int xVal,
                                int yVal)
Updates last point x and y values with new values

Parameters:
xVal - X coordinate of new point
yVal - Y corrdinate of new point
See Also:
mouseDragged
 o itemStateChanged
 public void itemStateChanged(ItemEvent e)
Updates current color, shape, or fill values based on which control was changed. If shape was changed, updateInstructions() is called to change instructions to those required by new shape.

Parameters:
e - ItemEvent object, used to check which control was changed and what value that control was changed to
See Also:
updateInstructions
 o actionPerformed
 public void actionPerformed(ActionEvent a)
Clears drawing area by repainting window

Parameters:
a - ActionEvent object