Class DrawingBoard

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

public class DrawingBoard
extends java.applet.Applet
implements java.awt.event.ActionListener, java.awt.event.ItemListener, java.awt.event.MouseMotionListener, java.awt.event.MouseListener

Drawing Board with controls allows to draw oval, rectangle, line and triangle extends Applet implements ActionListener for button controls, implements ItemListener for choice boxes, implements MouseMotionListener for rubber band drawing implements MouseListener for finishing the drawing

Version:
1.0
Author:
Julia Povarinets
See Also:
Serialized Form

Field Summary
 java.awt.Button b_circle
          declair window controls
 java.awt.Button b_clear
          declair window controls
 java.awt.Button b_line
          declair window controls
 java.awt.Button b_polygon
          declair window controls
 java.awt.Button b_rectangle
          declair window controls
 java.awt.Button b_undo
          declair window controls
 java.awt.Checkbox checkbox_filled
           
 java.awt.Choice choice_back_color
           
 java.awt.Choice choice_shape_color
           
 java.awt.Panel controls1
           
 java.awt.Panel controls2
           
 int currentShape
          declare variable to hold the current shape, initialize to oval
static int LINE
           
static int OVAL
          assign constants to be used in a switch statement that will determine the shape
static int POLYGON
           
static int RECTANGLE
           
 java.util.Vector shapeObjects
          create Vector object to hold the shape objects for repainting purposes
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
DrawingBoard()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          on the button click: if shape button is pressed, set the shape to be drawn if clear button is pressed, remove objects from vector and repaint if undo button is pressed, remove last odject from vector and repaint
 void drawRubberBand(int x1, int y1, int x2, int y2)
          draw the rubberband shape, by first erasing the previous, as mouse is dragged, then save the last points for the redraw on the next pass
 void init()
          initialization sets up the screen and controls
 void itemStateChanged(java.awt.event.ItemEvent event)
          this is used to change background color from the choice_back_color box
 void mouseClicked(java.awt.event.MouseEvent event)
          When drawing a triangle and mouse is clicked, use the saved points to call the drawShape method for the triangle.
 void mouseDragged(java.awt.event.MouseEvent event)
          when mouse is dragged: if drawing a triangle and mouse has been released before, call mouseMove event logic; set the coordinates and call drawRubberBand
 void mouseEntered(java.awt.event.MouseEvent event)
          displays a message on the status bar
 void mouseExited(java.awt.event.MouseEvent event)
          since event handling is implemented directly, have to implement all
 void mouseMoved(java.awt.event.MouseEvent event)
          draw the rubberband shape for the triangle, by first erasing the previous, as mouse moves, then save the previous points for the redraw on the next pass
 void mousePressed(java.awt.event.MouseEvent event)
          assign coordinates of initial point of the shape
 void mouseReleased(java.awt.event.MouseEvent event)
          When mouse is released, use the final point to call the drawShape method for the selected shape.
 void paint(java.awt.Graphics g)
          paintMethod - tell all shape objects in the Vector to repaint themselves.
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

b_circle

public java.awt.Button b_circle
declair window controls

b_rectangle

public java.awt.Button b_rectangle
declair window controls

b_line

public java.awt.Button b_line
declair window controls

b_polygon

public java.awt.Button b_polygon
declair window controls

b_clear

public java.awt.Button b_clear
declair window controls

b_undo

public java.awt.Button b_undo
declair window controls

choice_shape_color

public java.awt.Choice choice_shape_color

choice_back_color

public java.awt.Choice choice_back_color

checkbox_filled

public java.awt.Checkbox checkbox_filled

controls1

public java.awt.Panel controls1

controls2

public java.awt.Panel controls2

shapeObjects

public java.util.Vector shapeObjects
create Vector object to hold the shape objects for repainting purposes

OVAL

public static final int OVAL
assign constants to be used in a switch statement that will determine the shape

RECTANGLE

public static final int RECTANGLE

LINE

public static final int LINE

POLYGON

public static final int POLYGON

currentShape

public int currentShape
declare variable to hold the current shape, initialize to oval
Constructor Detail

DrawingBoard

public DrawingBoard()
Method Detail

init

public void init()
initialization sets up the screen and controls
Parameters:
none -  
Returns:
nothing
Overrides:
init in class java.applet.Applet

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
on the button click: if shape button is pressed, set the shape to be drawn if clear button is pressed, remove objects from vector and repaint if undo button is pressed, remove last odject from vector and repaint
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
ActionEvent - is passed in to get event
Returns:
nothing

itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent event)
this is used to change background color from the choice_back_color box
Specified by:
itemStateChanged in interface java.awt.event.ItemListener
Parameters:
ItemEvent - is passed in to get event
Returns:
nothing

drawRubberBand

public void drawRubberBand(int x1,
                           int y1,
                           int x2,
                           int y2)
draw the rubberband shape, by first erasing the previous, as mouse is dragged, then save the last points for the redraw on the next pass
Parameters:
x - and y coordinates from two points
Returns:
nothing

paint

public void paint(java.awt.Graphics g)
paintMethod - tell all shape objects in the Vector to repaint themselves. Also need this function for clearing screen and undoing shapes, since paint() is called by repaint()
Parameters:
Graphics - object
Returns:
nothing
Overrides:
paint in class java.awt.Container

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
when mouse is dragged: if drawing a triangle and mouse has been released before, call mouseMove event logic; set the coordinates and call drawRubberBand
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
MouseEvent - to get current coordinates
Returns:
nothing

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
assign coordinates of initial point of the shape
Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
MouseEvent - to get current coordinates
Returns:
nothing

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
When mouse is released, use the final point to call the drawShape method for the selected shape. Color is determined from the choice_shape_color box, filled status is determined from the checkbox. The shape object is then assigned to the Vector for repainting
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
MouseEvent - to get current coordinates
Returns:
nothing

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent event)
draw the rubberband shape for the triangle, by first erasing the previous, as mouse moves, then save the previous points for the redraw on the next pass
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
MouseEvent - to get current coordinates
Returns:
nothing

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)
since event handling is implemented directly, have to implement all
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent event)
displays a message on the status bar
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
When drawing a triangle and mouse is clicked, use the saved points to call the drawShape method for the triangle. Color is determined from the choice_shape_color box, filled status is determined from the checkbox. The triangle object is then assigned to the Vector for repainting
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
MouseEvent - to get current coordinates
Returns:
nothing