|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
gpdraw.DrawingTool
public class DrawingTool
DrawingTool is graphics environment that provides methods for a programmer
to draw pictures by moving an object (called a DrawingTool
)
around on the screen
The center of the graphics window is at location 0,0. Positive X is to
the right; positive Y is up. Headings (angles) are measured in degrees
counterclockwise from the positive X axis.
Field Summary |
---|
Fields inherited from class javax.swing.JFrame |
---|
EXIT_ON_CLOSE |
Fields inherited from class java.awt.Frame |
---|
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface javax.swing.WindowConstants |
---|
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
DrawingTool()
Constructor. |
|
DrawingTool(int width,
int height)
Constructor. |
|
DrawingTool(int width,
int height,
int delay)
Constructor. |
|
DrawingTool(SketchPad sPad)
Constructor. |
|
DrawingTool(SketchPad sPad,
int delay)
|
Method Summary | |
---|---|
void |
backward(double distance)
This DrawingTool object is moved backward from current direction by
distance pixels from the old (previous) location. |
void |
clear()
Clears the background to the current color |
void |
clear(java.awt.Color bg)
Clears the background to specified Color |
void |
clear(int colorCode)
Clears the background to the color specified by the given color code |
void |
down()
This object is set to drawing mode. |
void |
drawCircle(double radius)
If the object is in drawing mode, Draws a circle of radius radius
around the current location using the current width and color. |
void |
drawImage(java.lang.String fileName)
Loads and draws the image specified by the file name fileName . |
void |
drawImage(java.lang.String fileName,
double w,
double h)
Loads and draws the image specified by the file name fileName . |
void |
drawOval(double boundingBoxWidth,
double boundingBoxHeight)
Draws the outline of an oval. |
void |
drawRect(double recWidth,
double recHeight)
Draws the outline of the specified rectangle. |
void |
drawString(java.lang.String text)
Draw the string text at the current location using the
current color and font. |
void |
fillCircle(double radius)
Fills the specified circle. |
void |
fillOff()
Sets the drawing mode so that only the outline of all circle, oval and rectangle shapes are drawn.. |
void |
fillOn()
Sets the drawing mode so that all circle, oval and rectangle shapes are filled with the current color when drawn. |
void |
fillOval(double boundingBoxWidth,
double boundingBoxHeight)
Fills the specified oval. |
void |
fillRect(double recWidth,
double recHeight)
Fills the specified rectangle. |
void |
forward(double distance)
This DrawingTool object is moved forward from current direction by
distance pixels from the old (previous) location. |
java.awt.Color |
getBackgroundColor()
Gets the background color of the DrawingTool window |
java.awt.Color |
getColor()
Gets the color of the DrawingTool |
double |
getDirection()
Gets the direction of this DrawingTool
. |
int |
getHeight()
Get the height of the DrawingTool SketchPad window |
int |
getPenWidth()
Get the drawing width of the DrawingTool "pen" |
java.awt.geom.Point2D.Double |
getPosition()
Gets the x and y coordinates of the current
postion of this DrawingTool . |
int |
getWidth()
Get the width of the DrawingTool SketchPad window |
double |
getXPos()
Gets the x coordinate of the current postion of this
DrawingTool . |
double |
getYPos()
Gets the y coordinate of the current postion of this
DrawingTool . |
void |
home()
The location of the DrawingTool object is set to the center
of the SketchPad window with the drawing direction of the object set to up. |
boolean |
isDown()
Get the drawing width of the DrawingTool |
void |
keyPressed(int keyCode)
Invoked when a key has been pressed |
void |
keyTyped(char ch)
Invoked when a key has been typed |
void |
mouseClicked(double x,
double y)
Invoked when the mouse button has been clicked (pressed and released). |
void |
mouseDragged(double x,
double y)
Invoked when a mouse button is pressed on a component and then dragged. |
void |
move(double distance)
This DrawingTool object is moved in the current direction by
distance pixels from the old (previous) location. |
void |
move(double x,
double y)
This DrawingTool object is moved from the current position to the
position specified by the coordinates x and y. |
void |
move(int x,
int y)
|
void |
pause(int delay)
Pauses for delay milliseconds. |
void |
pixel(int x,
int y)
Plots a single pixel at the point (x, y) using the DrawingTool 's current color. |
void |
play(java.lang.String fileName)
Plays a wav or midi sound. |
void |
print()
Prints the DrawingTool SketchPad panel area confirming from
user with a print dialog |
void |
render()
Repaint the DrawingTool SketchPad panel. |
void |
save(java.lang.String fileName)
Write the DrawingTool SketchPad panel to a file. |
void |
setColor(java.awt.Color c)
The color of the DrawingTool object is set to c . |
void |
setColor(int colorCode)
The color of the DrawingTool object is set using the
colorCode as follows: |
void |
setColorHSB(int h,
int s,
int b)
The color of the DrawingTool object is set using
hue-saturation-brightness. |
void |
setColorRGB(int r,
int g,
int b)
The color of the DrawingTool object is set using red-green-blue. |
void |
setDirection(double d)
Sets the direction to d degrees. |
void |
setFont(java.awt.Font font)
|
void |
setWidth(int width)
Sets the width of the DrawingTool object is to
width pixels. |
java.lang.String |
toString()
Returns a string representation of this object. |
void |
translateOff()
Sets the origin of the DrawingTool SketchPad to the lower
left-hand corner of the window. |
void |
translateOn()
Sets the origin of the DrawingTool SketchPad to the center
of the window. |
void |
turn(double angle)
Changes the current direction counterclockwise by degrees
degrees from the current direction. |
void |
turnLeft(double degrees)
Changes the current direction counterclockwise by degrees
degrees from the current direction. |
void |
turnRight(double degrees)
Changes the current direction clockwise by degrees
degrees from the current direction |
void |
up()
This object is set to moving mode. |
Methods inherited from class javax.swing.JFrame |
---|
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, update |
Methods inherited from class java.awt.Frame |
---|
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated |
Methods inherited from class java.awt.Window |
---|
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, show, toBack, toFront |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusBackward, transferFocusDownCycle, validate |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.MenuContainer |
---|
getFont, postEvent |
Constructor Detail |
---|
public DrawingTool(SketchPad sPad, int delay)
public DrawingTool(SketchPad sPad)
DrawingTool
is created and placed in the
center (0, 0) of the SketchPad
. This object
is set to drawing mode. The direction for this object is
to the right (0 degrees). The DrawingTool
color
is set to black. The DrawingTool
width is 1.
public DrawingTool(int width, int height, int delay)
DrawingTool
window that is width
height pixels high with a drawing
delay of delay ms.
width
- width of this DrawingTool SketchPad
height
- height of this DrawingTool SketchPad
delay
- drawing delay (ms)public DrawingTool(int width, int height)
DrawingTool
window that is width
pixels wide by height
pixels high with no drawing
delay.
width
- width of this DrawingTool SketchPad
height
- height of this DrawingTool SketchPad
public DrawingTool()
DrawingTool
is created and placed in the
center (0, 0) of a SketchPad
window that is
500 pixels wide and 500 pixels high. This object is set
to drawing mode. The direction for this object is facing to
the right (0). The DrawingTool
color is set
to black. The DrawingTool
width is 1.
Method Detail |
---|
public int getWidth()
DrawingTool SketchPad
window
getWidth
in class java.awt.Component
DrawingTool SketchPad
windowpublic int getHeight()
DrawingTool SketchPad
window
getHeight
in class java.awt.Component
DrawingTool SketchPad
windowpublic int getPenWidth()
DrawingTool
"pen"
DrawingTool
"pen"public double getXPos()
x
coordinate of the current postion of this
DrawingTool
.
x
coordinate of this DrawingTool
public double getYPos()
y
coordinate of the current postion of this
DrawingTool
.
y
coordinate of this DrawingTool
public java.awt.geom.Point2D.Double getPosition()
x
and y
coordinates of the current
postion of this DrawingTool
.
x
and y
coordinates of the current
postion of this DrawingTool
as a
Point2D.Double
.public double getDirection()
DrawingTool
.
DrawingTool
in degreespublic boolean isDown()
DrawingTool
true
if this DrawingTool
is in drawing
mode (down); false
otherwisepublic java.awt.Color getColor()
DrawingTool
DrawingTool
public java.awt.Color getBackgroundColor()
DrawingTool
window
DrawingTool
windowpublic void home()
DrawingTool
object is set to the center
of the SketchPad window with the drawing direction of the object set to up.
public void down()
public void up()
public void translateOn()
DrawingTool SketchPad
to the center
of the window.
public void translateOff()
DrawingTool SketchPad
to the lower
left-hand corner of the window.
public void fillOn()
public void fillOff()
public void setDirection(double d)
d
degrees counterclockwise from the positive x-axis
d
- degrees counterclockwise from the positive x-axispublic void setWidth(int width)
DrawingTool
object is to
width
pixels.
width
- width in pixels of the DrawingTool
object
java.lang.RuntimeException
- if width is < 1public void clear()
public void clear(java.awt.Color bg)
Color
bg
- Color
of the resulting cleared backgroundpublic void clear(int colorCode)
colorCode
- code used to specify the color of the resulting cleared
backgroundsetColor(int colorCode)
public void pause(int delay)
delay
milliseconds. Also invokes a repaint
of the display area.
delay
- number of ms to delaypublic void setColor(java.awt.Color c)
DrawingTool
object is set to c
.
c
- a valid Color
objectpublic void setColorRGB(int r, int g, int b)
DrawingTool
object is set using red-green-blue.
r
- the red componentg
- the green componentb
- the blue componentpublic void setColorHSB(int h, int s, int b)
DrawingTool
object is set using
hue-saturation-brightness.
h
- the hue components
- the saturation of the colorb
- the brightness of the colorpublic void setColor(int colorCode)
DrawingTool
object is set using the
colorCode
as follows:
colorCode
- a valid colorCode
public void setFont(java.awt.Font font)
setFont
in class java.awt.Container
public void move(int x, int y)
move
in class java.awt.Component
public void move(double x, double y)
DrawingTool
object is moved from the current position to the
position specified by the coordinates x and y. If this object is in
drawing mode, a line segment is drawn from the old (previous) position
to the absolute position specified by x and y. The direction is changed
to the heading given by the move from the previous postion to the current
position.
x
- x coordinate of destinationy
- y coordinate of destinationpublic void move(double distance)
DrawingTool
object is moved in the current direction by
distance
pixels from the old (previous) location.
If this object is in drawing mode, a line segment is drawn across
the distance
path just traversed.
distance
- pixels to move from the current locationpublic void forward(double distance)
DrawingTool
object is moved forward from current direction by
distance
pixels from the old (previous) location. If this
object is in drawing mode, a line segment is drawn across the distance
path just traversed. The direction is unchanged. A delay occurs following
this methods execution.
distance
- pixels to move forwards from the current locationpublic void backward(double distance)
DrawingTool
object is moved backward from current direction by
distance
pixels from the old (previous) location. If this
object is in drawing mode, a line segment is drawn across the distance
path just traversed. The direction is unchanged. A delay occurs following
this methods execution.
distance
- pixels to move backwards from the current locationpublic void pixel(int x, int y)
DrawingTool
's current color.
x
- x coordinate of the pixel to be drawny
- y coordinate of the pixel to be drawnpublic void fillRect(double recWidth, double recHeight)
x - recWidth/2
and x + recWidth/2
.
The top and bottom edges are at y - recHeight/2
and
y + recHeight/2
. The rectangle is filled using the
DrawingTool
's current color.
recWidth
- width of the rectangle to be filledrecHeight
- height of the rectangle to be filledpublic void drawRect(double recWidth, double recHeight)
x - recWidth/2
and x + recWidth/2
.
The top and bottom edges are at y - recHeight/2
and
y + recHeight/2
. The rectangle is drawn using the
DrawingTool
's current color.
recWidth
- width of the rectangle to be drawnrecHeight
- height of the rectangle to be drawnpublic void fillCircle(double radius)
radius
centered around the current drawing position
The circle is drawn using the DrawingTool
's current color.
radius
- radius of circle to be drawnpublic void drawCircle(double radius)
radius
around the current location using the current width and color.
radius
- radius of circle to be drawnpublic void fillOval(double boundingBoxWidth, double boundingBoxHeight)
width
, and height
arguments.
The left and right edges of the bounding rectangle are at
x - recWidth/2
and x + recWidth/2
.
The top and bottom edges are at y - recHeight/2
and
y + recHeight/2
. The oval is drawn using the
DrawingTool
's current color.
boundingBoxWidth
- width of the oval to be filledboundingBoxHeight
- height of the oval to be filledpublic void drawOval(double boundingBoxWidth, double boundingBoxHeight)
width
, and height
arguments.
The left and right edges of the bounding rectangle are at
x - recWidth/2
and x + recWidth/2
.
The top and bottom edges are at y - recHeight/2
and
y + recHeight/2
. The oval is drawn using the
DrawingTool
's current color.
boundingBoxWidth
- width of the oval to be drawnboundingBoxHeight
- height of the oval to be drawnpublic void drawImage(java.lang.String fileName)
fileName
.
The image is centered at the current drawing location.
fileName
- file name of image to load and drawpublic void drawImage(java.lang.String fileName, double w, double h)
fileName
.
The image is centered at the current drawing location and scaled of size w-by-h.
fileName
- file name of image to load and draww
- width of bounding box in which the image is drawnh
- height of bounding box in which the image is drawnpublic void turn(double angle)
degrees
degrees from the current direction.
angle
- degrees counterclockwise from the current directionpublic void turnLeft(double degrees)
degrees
degrees from the current direction.
degrees
- degrees counterclockwise from the current directionpublic void turnRight(double degrees)
degrees
degrees from the current direction
degrees
- degrees clockwise from the current directionpublic void play(java.lang.String fileName)
fileName
- name of the sound filepublic void drawString(java.lang.String text)
text
at the current location using the
current color and font.
text
- string to be drawnpublic void render()
DrawingTool SketchPad
panel.
public void save(java.lang.String fileName)
DrawingTool SketchPad
panel to a file.
The suffix of the file name can be png, jpg, or gif and will determine
the format of the graphics file that is written.
fileName
- Name of file to be writtenpublic void print()
DrawingTool SketchPad
panel area confirming from
user with a print dialog
public java.lang.String toString()
toString
in class java.awt.Component
public void mouseClicked(double x, double y)
SketchPadListener
mouseClicked
in interface SketchPadListener
public void mouseDragged(double x, double y)
SketchPadListener
mouseDragged
events will continue to be delivered to the
component where the drag originated until the mouse button is released
mouseDragged
in interface SketchPadListener
public void keyPressed(int keyCode)
SketchPadListener
keyPressed
in interface SketchPadListener
public void keyTyped(char ch)
SketchPadListener
keyTyped
in interface SketchPadListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |