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:
- Rectangles
- Ovals
- Triangles
- Lines
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
-
clear
-
-
colors
-
-
filled
-
-
instructions
-
-
shapes
-
-
DrawPad()
-
-
actionPerformed(ActionEvent)
-
Clears drawing area by repainting window
-
changeLastPoint(int, int)
-
Updates
last
point x and y values with new values
-
init()
-
Initialization routine for the
DrawPad
class.
-
itemStateChanged(ItemEvent)
-
Updates current color, shape, or fill values based on which control
was changed.
-
mouseClicked(MouseEvent)
-
Records the point where the mouse is clicked during the
creation of a triangle.
-
mouseDragged(MouseEvent)
-
Records current point.
-
mouseEnter(MouseEvent)
-
Dummy event inserted for MouseListener interface
-
mouseEntered(MouseEvent)
-
Dummy event inserted for MouseListener interface
-
mouseExited(MouseEvent)
-
Dummy event inserted for MouseListener interface
-
mouseMoved(MouseEvent)
-
Creates rubberbanding effect for creation of triangle.
-
mousePressed(MouseEvent)
-
Records the point where the mouse is pressed to be used as an
origin point for the shape being drawn.
-
mouseReleased(MouseEvent)
-
Records point where mouse button is released and draws appropriate
shape, filling if needed.
-
updateInstructions()
-
Updates drawing instructions in window based on what shape is
selected in the choice box.
colors
public Choice colors
shapes
public Choice shapes
filled
public Checkbox filled
instructions
public Label instructions
clear
public Button clear
DrawPad
public DrawPad()
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
mouseEntered
public void mouseEntered(MouseEvent e)
- Dummy event inserted for MouseListener interface
- Parameters:
- e - MouseEvent object
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
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
mouseExited
public void mouseExited(MouseEvent e)
- Dummy event inserted for MouseListener interface
- Parameters:
- e - MouseEvent object
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
mouseEnter
public void mouseEnter(MouseEvent e)
- Dummy event inserted for MouseListener interface
- Parameters:
- e - MouseEvent object
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
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
updateInstructions
protected void updateInstructions()
- Updates drawing instructions in window based on what shape is
selected in the choice box.
- See Also:
- itemStateChanged
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
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
actionPerformed
public void actionPerformed(ActionEvent a)
- Clears drawing area by repainting window
- Parameters:
- a - ActionEvent object