|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgpdraw.Pen
public class Pen
Pen is graphics environment that provides methods for a programmer
to draw pictures by moving an object (called a Pen
)
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.
Method Summary | |
---|---|
static void |
backward(double distance)
This drawing position is moved backward from current location by distance pixels from the old (previous) location. |
static void |
clear()
Clears the background to the current color |
static void |
clear(java.awt.Color bg)
Clears the background to specified Color |
static void |
clear(int colorCode)
Clears the background to the color specified by the given color code |
static void |
create(int width,
int height)
Create a canvas with drawing area that is width height pixels high. |
static void |
create(int width,
int height,
int dly)
Create a canvas with drawing area that is width height pixels high with a drawing
delay of delay ms. |
static void |
destroy()
|
static void |
down()
Sets drawing mode to true. |
static void |
drawCircle(double r)
If the object is in drawing mode, Draws a circle of radius radius
around the current location using the current width and color. |
static void |
drawImage(java.lang.String fileName)
Loads and draws the image specified by the file name fileName . |
static void |
drawImage(java.lang.String fileName,
double w,
double h)
Loads and draws the image specified by the file name fileName . |
static void |
drawOval(double w,
double h)
Draws the outline of an oval. |
static void |
drawRect(double w,
double h)
Draws the outline of the specified rectangle. |
static void |
drawString(java.lang.String s)
Draw the string text at the current location using the
current color and font. |
static void |
fillCircle(double r)
Fills the specified circle. |
static void |
fillOff()
Sets the drawing mode so that only the outline of all circle, oval and rectangle shapes are drawn.. |
static void |
fillOn()
Sets the drawing mode so that all circle, oval and rectangle shapes are filled with the current color when drawn. |
static void |
fillOval(double w,
double h)
Fills the specified oval. |
static void |
fillRect(double w,
double h)
Fills the specified rectangle. |
static void |
forward(double distance)
This drawing position is moved forward from current location by distance pixels from the old (previous) location. |
static java.awt.Color |
getBackgroundColor()
Gets the background color of the drawing area |
static java.awt.Color |
getColor()
Gets the color of the Pen |
static double |
getDirection()
Gets the current drawing orientation. |
boolean |
getFill()
Get the state of the fill flag |
static int |
getHeight()
Get the height of the drawing area |
int |
getPenWidth()
Get the drawing width of the Pen |
static java.awt.geom.Point2D.Double |
getPosition()
Gets the x and y coordinates of the current
postion of the current drawing position. |
boolean |
getTranslate()
Get the state of the translation flag |
static int |
getWidth()
Get the width of the drawing area |
static double |
getXPos()
Gets the x coordinate of the current Pen postion |
static double |
getYPos()
Gets the y coordinate of the current Pen postion |
static void |
home()
The drawing location is set to the center of the drawing area with the drawing direction set to the right. |
static boolean |
isDown()
Get the drawing state of the Pen |
static void |
move(double d)
This drawing position is moved in the current direction by distance pixels from the old (previous) location. |
static void |
move(double x,
double y)
This drawing position is moved from the current position to the position specified by the coordinates x and y. |
static void |
move(int x,
int y)
|
static void |
pause(int delay)
Pauses for delay milliseconds. |
static void |
pixel(int x,
int y)
Plots a single pixel at the point (x, y) using the current drawing color. |
static void |
play(java.lang.String fileName)
Plays a wav or midi sound. |
static void |
print()
Prints the SketchPad panel area confirming from
user with a print dialog |
static void |
render()
Repaint the drawing area. |
static void |
save(java.lang.String fileName)
Write the display area to a file. |
static void |
setColor(java.awt.Color c)
The foreground drawing color is set to c . |
static void |
setColor(int colorCode)
The color of the Pen is set using the colorCode as follows: |
static void |
setColorHSB(int h,
int s,
int b)
The foreground drawing color is set using hue-saturation-brightness. |
static void |
setColorRGB(int r,
int g,
int b)
The foreground drawing color is set using red-green-blue. |
static void |
setDirection(double d)
Sets the direction to d degrees. |
static void |
setFont(java.awt.Font font)
|
static void |
setWidth(int width)
Sets the drawing width to width pixels. |
static void |
translateOff()
Sets the origin of the drawing area to the lower left-hand corner of the window. |
static void |
translateOn()
Sets the origin of the drawing area to the center of the window. |
static void |
turn(double angle)
Changes the current direction counterclockwise by angle
degrees from the current direction |
static void |
turnLeft(double degrees)
Changes the current direction counterclockwise by degrees
degrees from the current direction |
static void |
turnRight(double degrees)
Changes the current direction clockwise by degrees
degrees from the current direction |
static void |
up()
Sets drawing mode to false (movement mode). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void create(int width, int height, int dly)
width
height pixels high with a drawing
delay of delay ms.
width
- width of this DrawingTool SketchPad
height
- height of this DrawingTool SketchPad
dly
- drawing delay (ms)public static void create(int width, int height)
width
height pixels high.
width
- width of this DrawingTool SketchPad
height
- height of this DrawingTool SketchPad
public static void destroy()
public static int getWidth()
public static int getHeight()
public static double getXPos()
x
coordinate of the current Pen postion
x
coordinate of the current Pen postionpublic static double getYPos()
y
coordinate of the current Pen postion
y
coordinate of the current Pen postionpublic static double getDirection()
public static boolean isDown()
true
if in drawing mode (Pen is down);
false
otherwisepublic static java.awt.Color getColor()
public static java.awt.Color getBackgroundColor()
public static java.awt.geom.Point2D.Double getPosition()
x
and y
coordinates of the current
postion of the current drawing position.
x
and y
coordinates of the current
postion as a Point2D.Double
.public int getPenWidth()
public boolean getFill()
true
if in fill mode, false
otherwise.public boolean getTranslate()
true
if in translation mode, false
otherwise.public static void home()
public static void down()
public static void up()
public static void translateOn()
public static void translateOff()
public static void fillOn()
public static void fillOff()
public static void setDirection(double d)
d
degrees counterclockwise from the positive x-axis
d
- degrees counterclockwise from the positive x-axispublic static void setWidth(int width)
width
pixels.
width
- drawing width in pixels
java.lang.RuntimeException
- if width is < 1public static void clear()
public static void clear(java.awt.Color bg)
Color
bg
- Color
of the resulting cleared backgroundpublic static void clear(int colorCode)
colorCode
- code used to specify the color of the resulting cleared
backgroundsetColor(int colorCode)
public static void pause(int delay)
delay
milliseconds. Also invokes a repaint
of the display area.
delay
- number of ms to delaypublic static void setColor(java.awt.Color c)
c
.
c
- a valid Color
objectpublic static void setColorRGB(int r, int g, int b)
r
- the red componentg
- the green componentb
- the blue componentpublic static void setColorHSB(int h, int s, int b)
h
- the hue components
- the saturation of the colorb
- the brightness of the colorpublic static void setColor(int colorCode)
colorCode
as follows:
colorCode
- a valid colorCode
public static void setFont(java.awt.Font font)
public static void move(int x, int y)
public static void move(double x, double y)
x
- x coordinate of destinationy
- y coordinate of destinationpublic static void move(double d)
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.
d
- pixels to move from the current locationpublic static void forward(double distance)
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 static void backward(double distance)
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 static void pixel(int x, int y)
x
- x coordinate of the pixel to be drawny
- y coordinate of the pixel to be drawnpublic static void fillRect(double w, double h)
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.Degenerates to single pixel if
the rectangle is too small.
w
- width of the rectangle to be filledh
- height of the rectangle to be filledpublic static void drawRect(double w, double h)
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. Degenerates to single pixel if
the rectangle is too small.
w
- width of the rectangle to be drawnh
- height of the rectangle to be drawnpublic static void fillCircle(double r)
radius
centered around the current drawing position
The circle is drawn using the DrawingTool
's current color.
Degenerates to single pixel if the circle is too small.
r
- radius of circle to be drawnpublic static void drawCircle(double r)
radius
around the current location using the current width and color. Degenerates
to single pixel if the circle is too small.
r
- radius of circle to be drawnpublic static void fillOval(double w, double h)
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. Degenerates to single pixel if
the oval is too small.
w
- width of the oval to be filledh
- height of the oval to be filledpublic static void drawOval(double w, double h)
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. Degenerates to single pixel if
the oval is too small.
w
- width of the oval to be drawnh
- height of the oval to be drawnpublic static 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 static 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 static void turn(double angle)
angle
degrees from the current direction
angle
- degrees counterclockwise from the current directionpublic static void turnLeft(double degrees)
degrees
degrees from the current direction
degrees
- degrees counterclockwise from the current directionpublic static void turnRight(double degrees)
degrees
degrees from the current direction
degrees
- degrees clockwise from the current directionpublic static void play(java.lang.String fileName)
fileName
- name of the sound filepublic static void drawString(java.lang.String s)
text
at the current location using the
current color and font.
s
- string to be drawnpublic static void render()
public static void save(java.lang.String fileName)
fileName
- Name of file to be writtenpublic static void print()
SketchPad
panel area confirming from
user with a print dialog
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |