|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object acm.graphics.GObject acm.graphics.GPen
public class GPen
The GPen
class simulates a pen drawing on a canvas.
As with the other graphical objects in the
acm.graphics
package, you use this class by constructing a new GPen
object and adding that object to a GCanvas
.
You can move the pen on the canvas by using the methods
setLocation and
move and then
draw lines using drawLine.
The GPen
object remembers the series of lines
and can therefore repaint the screen image when necessary.
Constructor Summary | |
---|---|
GPen()
Creates a new GPen object with an empty path. |
|
GPen(double x,
double y)
Creates a new GPen object with an empty path, initially
positioned at the point (x , y ). |
Method Summary | |
---|---|
boolean |
contains(double x,
double y)
Contains is defined to be false for the GPen object to avoid having the
trace intercept mouse clicks. |
void |
drawLine(double dx,
double dy)
Draws a line segment with displacements dx and dy . |
protected void |
drawPen(Graphics g)
This method draws a representation of the pen at the current location. |
void |
drawPolarLine(double r,
double theta)
Draws a line segment using displacements given in polar coordinates. |
void |
endFilledRegion()
Ends the definition of a region and fills it with the current color. |
void |
erasePath()
Erases the entire path drawn by the pen but does not change its position. |
GRectangle |
getBounds()
Returns the bounding box for the entire figure traced by the pen. |
Color |
getFillColor()
Returns the color used to display the filled region of this object. |
protected Rectangle |
getPenBounds()
This method returns the bounds that the pen occupies. |
Image |
getPenImage()
Returns the image used to draw the pen when setPenVisible has been
called. |
double |
getSpeed()
Returns the current speed of the pen. |
void |
hidePen()
Makes the pen itself invisible. |
boolean |
isPenVisible()
Returns whether the pen is visible. |
void |
paint(Graphics g)
Implements the paint operation for this graphical object. |
void |
scale(double sx,
double sy)
Sets the scale factors sx and sy . |
void |
setColor(Color color)
Sets the color of the pen. |
void |
setFillColor(Color color)
Sets the color used to fill a region. |
void |
setLocation(double x,
double y)
Moves the pen to the point ( x , y ) without drawing a line. |
void |
setPenImage(Image image)
Sets the image of the pen to be the specified image. |
void |
setSpeed(double speed)
Sets the speed of the pen, which must be a number between 0 (slowest) and 1 (fastest). |
void |
showPen()
Makes the pen itself visible. |
void |
startFilledRegion()
Starts defining a region that will be filled with the current color. |
Methods inherited from class acm.graphics.GObject |
---|
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, colorName, contains, fireActionEvent, fireActionEvent, fireMouseListeners, getColor, getComponent, getHeight, getLocation, getObjectColor, getParent, getSize, getWidth, getX, getY, isVisible, move, movePolar, paintObject, paramString, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, sendBackward, sendForward, sendToBack, sendToFront, setLocation, setParent, setVisible, start, start, toString, updateEnabledList |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public GPen()
GPen
object with an empty path.
public GPen(double x, double y)
GPen
object with an empty path, initially
positioned at the point (x
, y
).
x
- The initial x coordinate of the peny
- The initial y coordinate of the penMethod Detail |
---|
public boolean contains(double x, double y)
GPen
object to avoid having the
trace intercept mouse clicks.
contains
in class GObject
x
- The x-coordinate of the point being testedy
- The y-coordinate of the point being tested
true
if the point (x
, y
) is inside
the object, and false
otherwisepublic void drawLine(double dx, double dy)
dx
and dy
.
Drawing a line leaves the pen positioned at the end of the line segment, so
that the next call to drawLine
will continue from where this
one finished.
dx
- The extent of the line in the x directiondy
- The extent of the line in the y directionprotected void drawPen(Graphics g)
g
- The graphics context in which to draw the penpublic final void drawPolarLine(double r, double theta)
r
specifies the length of the line segment, and
theta
specifies the angle at which the line is drawn. The
angle is measured in degrees increasing counterclockwise from the +x axis.
Thus, the call
drawPolarLine(1.0, 0);
draws a line extending rightward one inch from the current point. Similarly
drawPolarLine(2.0, 135);
draws a two-inch line extending to the northwest from the current point.
r
- The length of the line segmenttheta
- The angle at which to draw the line, measured in degrees
increasing counterclockwise from the +x axispublic void endFilledRegion()
public void erasePath()
public GRectangle getBounds()
getBounds
in class GObject
GRectangle
representing the bounding boxpublic Color getFillColor()
getFillColor
returns the color of the
object.
protected Rectangle getPenBounds()
public Image getPenImage()
setPenVisible
has been
called.
public double getSpeed()
public void hidePen()
public boolean isPenVisible()
true
if the pen is visible, otherwise false
public void paint(Graphics g)
paint
operation for this graphical object. This method
is not called directly by clients.
paint
in class GObject
g
- The graphics context into which the painting is donepublic void scale(double sx, double sy)
sx
and sy
. Scaling a GPen
object changes the location of points as well the size of line segments. This
behavior seems counterintuitive for a pen installed directly in a GCanvas
,
but is quite useful when a GPen
is embedded in a compound object.
sx
- The factor used to scale all coordinates in the x directionsy
- The factor used to scale all coordinates in the y directionpublic void setColor(Color color)
setColor
in class GObject
color
- The new color for the penpublic void setFillColor(Color color)
color
- The new color used to fill a regionpublic void setLocation(double x, double y)
x
, y
) without drawing a line.
setLocation
in class GObject
x
- The x-coordinate of the new positiony
- The y-coordinate of the new positionpublic void setPenImage(Image image)
image
- The new image to use for the penpublic void setSpeed(double speed)
speed
- The speed of the pen (0 is slowest, 1 is fastest)public void showPen()
drawPen
method will be called at the end of painting the path to show the current location.
public void startFilledRegion()
endFilledRegion
will be used to create a polygon that
is then filled.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |