|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Panel | +--java.applet.Applet | +--DrawingBoard
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
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 |
public java.awt.Button b_circle
public java.awt.Button b_rectangle
public java.awt.Button b_line
public java.awt.Button b_polygon
public java.awt.Button b_clear
public java.awt.Button b_undo
public java.awt.Choice choice_shape_color
public java.awt.Choice choice_back_color
public java.awt.Checkbox checkbox_filled
public java.awt.Panel controls1
public java.awt.Panel controls2
public java.util.Vector shapeObjects
public static final int OVAL
public static final int RECTANGLE
public static final int LINE
public static final int POLYGON
public int currentShape
Constructor Detail |
public DrawingBoard()
Method Detail |
public void init()
none
- public void actionPerformed(java.awt.event.ActionEvent event)
ActionEvent
- is passed in to get eventpublic void itemStateChanged(java.awt.event.ItemEvent event)
ItemEvent
- is passed in to get eventpublic void drawRubberBand(int x1, int y1, int x2, int y2)
x
- and y coordinates from two pointspublic void paint(java.awt.Graphics g)
Graphics
- objectpublic void mouseDragged(java.awt.event.MouseEvent event)
MouseEvent
- to get current coordinatespublic void mousePressed(java.awt.event.MouseEvent event)
MouseEvent
- to get current coordinatespublic void mouseReleased(java.awt.event.MouseEvent event)
MouseEvent
- to get current coordinatespublic void mouseMoved(java.awt.event.MouseEvent event)
MouseEvent
- to get current coordinatespublic void mouseExited(java.awt.event.MouseEvent event)
public void mouseEntered(java.awt.event.MouseEvent event)
public void mouseClicked(java.awt.event.MouseEvent event)
MouseEvent
- to get current coordinates
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |