类 Draw
- java.lang.Object
-
- edu.princeton.cs.algs4.Draw
-
- 所有已实现的接口:
java.awt.event.ActionListener
,java.awt.event.KeyListener
,java.awt.event.MouseListener
,java.awt.event.MouseMotionListener
,java.util.EventListener
public final class Draw extends java.lang.Object implements java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListener
Draw. This class provides a basic capability for creating drawings with your programs. It uses a simple graphics model that allows you to create drawings consisting of points, lines, and curves in a window on your computer and to save the drawings to a file. This is the object-oriented version of standard draw; it supports multiple indepedent drawing windows.For additional documentation, see Section 3.1 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
-
-
字段概要
字段 修饰符和类型 字段 说明 static java.awt.Color
BLACK
The color black.static java.awt.Color
BLUE
The color blue.static java.awt.Color
BOOK_BLUE
Shade of blue used in Introduction to Programming in Java.static java.awt.Color
BOOK_LIGHT_BLUE
Shade of light blue used in Introduction to Programming in Java.static java.awt.Color
BOOK_RED
Shade of red used in Algorithms, 4th edition.static java.awt.Color
CYAN
The color cyan.static java.awt.Color
DARK_GRAY
The color dark gray.static java.awt.Color
GRAY
The color gray.static java.awt.Color
GREEN
The color green.static java.awt.Color
LIGHT_GRAY
The color light gray.static java.awt.Color
MAGENTA
The color magenta.static java.awt.Color
ORANGE
The color orange.static java.awt.Color
PINK
The color pink.static java.awt.Color
PRINCETON_ORANGE
Shade of orange used in Princeton's identity.static java.awt.Color
RED
The color red.static java.awt.Color
WHITE
The color white.static java.awt.Color
YELLOW
The color yellow.
-
方法概要
修饰符和类型 方法 说明 void
actionPerformed(java.awt.event.ActionEvent e)
This method cannot be called directly.void
addListener(DrawListener listener)
Adds aDrawListener
to listen to keyboard and mouse events.void
arc(double x, double y, double radius, double angle1, double angle2)
Draws a circular arc of the specified radius, centered at (x, y), from angle1 to angle2 (in degrees).void
circle(double x, double y, double radius)
Draws a circle of the specified radius, centered at (x, y).void
clear()
Clears the screen to the default color (white).void
clear(java.awt.Color color)
Clears the screen to the given color.void
disableDoubleBuffering()
Disable double buffering.void
ellipse(double x, double y, double semiMajorAxis, double semiMinorAxis)
Draws an ellipse with the specified semimajor and semiminor axes, centered at (x, y).void
enableDoubleBuffering()
Enable double buffering.void
filledCircle(double x, double y, double radius)
Draws a filled circle of the specified radius, centered at (x, y).void
filledEllipse(double x, double y, double semiMajorAxis, double semiMinorAxis)
Draws a filled ellipse with the specified semimajor and semiminor axes, centered at (x, y).void
filledPolygon(double[] x, double[] y)
Draws a filled polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).void
filledRectangle(double x, double y, double halfWidth, double halfHeight)
Draws a filled rectangle of the specified size, centered at (x, y).void
filledSquare(double x, double y, double halfLength)
Draws a square of the specified size, centered at (x, y).java.awt.Font
getFont()
Gets the current font.javax.swing.JLabel
getJLabel()
Gets the currentJLabel
for use in some other GUI.java.awt.Color
getPenColor()
Gets the current pen color.double
getPenRadius()
Gets the current pen radius.boolean
hasNextKeyTyped()
Returns true if the user has typed a key.boolean
isKeyPressed(int keycode)
Returns true if the keycode is being pressed.boolean
isMousePressed()
Returns true if the mouse is being pressed.void
keyPressed(java.awt.event.KeyEvent e)
This method cannot be called directly.void
keyReleased(java.awt.event.KeyEvent e)
This method cannot be called directly.void
keyTyped(java.awt.event.KeyEvent e)
This method cannot be called directly.void
line(double x0, double y0, double x1, double y1)
Draws a line from (x0, y0) to (x1, y1).static void
main(java.lang.String[] args)
Test client.void
mouseClicked(java.awt.event.MouseEvent e)
This method cannot be called directly.void
mouseDragged(java.awt.event.MouseEvent e)
This method cannot be called directly.void
mouseEntered(java.awt.event.MouseEvent e)
This method cannot be called directly.void
mouseExited(java.awt.event.MouseEvent e)
This method cannot be called directly.void
mouseMoved(java.awt.event.MouseEvent e)
This method cannot be called directly.boolean
mousePressed()
已过时。replaced byisMousePressed()
void
mousePressed(java.awt.event.MouseEvent e)
This method cannot be called directly.void
mouseReleased(java.awt.event.MouseEvent e)
This method cannot be called directly.double
mouseX()
Returns the x-coordinate of the mouse.double
mouseY()
Returns the y-coordinate of the mouse.char
nextKeyTyped()
The next key typed by the user.void
pause(int t)
Pause for t milliseconds.void
picture(double x, double y, java.lang.String filename)
Draws the specified image centered at (x, y).void
picture(double x, double y, java.lang.String filename, double degrees)
Draws the specified image centered at (x, y), rotated given number of degrees.void
picture(double x, double y, java.lang.String filename, double scaledWidth, double scaledHeight)
Draws the specified image centered at (x, y), rescaled to the specified bounding box.void
picture(double x, double y, java.lang.String filename, double scaledWidth, double scaledHeight, double degrees)
Draws the specified image centered at (x, y), rotated given number of degrees, and rescaled to the specified bounding box.void
point(double x, double y)
Draws a point at (x, y).void
polygon(double[] x, double[] y)
Draws a polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).void
rectangle(double x, double y, double halfWidth, double halfHeight)
Draws a rectangle of the specified size, centered at (x, y).void
save(java.lang.String filename)
Saves the drawing to using the specified filename.void
setCanvasSize(int canvasWidth, int canvasHeight)
Sets the canvas (drawing area) to be width-by-height pixels.void
setDefaultCloseOperation(int value)
Sets the default close operation.void
setFont()
Sets the font to the default font (sans serif, 16 point).void
setFont(java.awt.Font font)
Sets the font to the given value.void
setLocationOnScreen(int x, int y)
Sets the upper-left hand corner of the drawing window to be (x, y), where (0, 0) is upper left.void
setPenColor()
Sets the pen color to the default color (black).void
setPenColor(int red, int green, int blue)
Sets the pen color to the given RGB color.void
setPenColor(java.awt.Color color)
Sets the pen color to the given color.void
setPenRadius()
Sets the pen size to the default (.002).void
setPenRadius(double radius)
Sets the radius of the pen to the given size.void
setXscale()
Sets the x-scale to be the default (between 0.0 and 1.0).void
setXscale(double min, double max)
Sets the x-scale.void
setYscale()
Sets the y-scale to be the default (between 0.0 and 1.0).void
setYscale(double min, double max)
Sets the y-scale.void
show()
Copies offscreen buffer to onscreen buffer.void
show(int t)
已过时。void
square(double x, double y, double halfLength)
Draws a square of the specified size, centered at (x, y).void
text(double x, double y, java.lang.String text)
Writes the given text string in the current font, centered at (x, y).void
text(double x, double y, java.lang.String text, double degrees)
Writes the given text string in the current font, centered at (x, y) and rotated by the specified number of degrees.void
textLeft(double x, double y, java.lang.String text)
Writes the given text string in the current font, left-aligned at (x, y).void
textRight(double x, double y, java.lang.String text)
Writes the given text string in the current font, right-aligned at (x, y).void
xorOff()
Turns off xor mode.void
xorOn()
Turns on xor mode.
-
-
-
字段详细资料
-
BLACK
public static final java.awt.Color BLACK
The color black.
-
BLUE
public static final java.awt.Color BLUE
The color blue.
-
CYAN
public static final java.awt.Color CYAN
The color cyan.
-
DARK_GRAY
public static final java.awt.Color DARK_GRAY
The color dark gray.
-
GRAY
public static final java.awt.Color GRAY
The color gray.
-
GREEN
public static final java.awt.Color GREEN
The color green.
-
LIGHT_GRAY
public static final java.awt.Color LIGHT_GRAY
The color light gray.
-
MAGENTA
public static final java.awt.Color MAGENTA
The color magenta.
-
ORANGE
public static final java.awt.Color ORANGE
The color orange.
-
PINK
public static final java.awt.Color PINK
The color pink.
-
RED
public static final java.awt.Color RED
The color red.
-
WHITE
public static final java.awt.Color WHITE
The color white.
-
YELLOW
public static final java.awt.Color YELLOW
The color yellow.
-
BOOK_BLUE
public static final java.awt.Color BOOK_BLUE
Shade of blue used in Introduction to Programming in Java. It is Pantone 300U. The RGB values are approximately (9, 90, 166).
-
BOOK_LIGHT_BLUE
public static final java.awt.Color BOOK_LIGHT_BLUE
Shade of light blue used in Introduction to Programming in Java. The RGB values are approximately (103, 198, 243).
-
BOOK_RED
public static final java.awt.Color BOOK_RED
Shade of red used in Algorithms, 4th edition. It is Pantone 1805U. The RGB values are approximately (150, 35, 31).
-
PRINCETON_ORANGE
public static final java.awt.Color PRINCETON_ORANGE
Shade of orange used in Princeton's identity. It is PMS 158. The RGB values are approximately (245, 128, 37).
-
-
方法详细资料
-
setLocationOnScreen
public void setLocationOnScreen(int x, int y)
Sets the upper-left hand corner of the drawing window to be (x, y), where (0, 0) is upper left.- 参数:
x
- the number of pixels from the lefty
- the number of pixels from the top- 抛出:
java.lang.IllegalArgumentException
- if the width or height is 0 or negative
-
setDefaultCloseOperation
public void setDefaultCloseOperation(int value)
Sets the default close operation.- 参数:
value
- the value, typicallyJFrame.EXIT_ON_CLOSE
(close all windows) orJFrame.DISPOSE_ON_CLOSE
(close current window)
-
setCanvasSize
public void setCanvasSize(int canvasWidth, int canvasHeight)
Sets the canvas (drawing area) to be width-by-height pixels. This also erases the current drawing and resets the coordinate system, pen radius, pen color, and font back to their default values. Ordinarly, this method is called once, at the very beginning of a program.- 参数:
canvasWidth
- the width as a number of pixelscanvasHeight
- the height as a number of pixels- 抛出:
java.lang.IllegalArgumentException
- unless bothcanvasWidth
andcanvasHeight
are positive
-
setXscale
public void setXscale()
Sets the x-scale to be the default (between 0.0 and 1.0).
-
setYscale
public void setYscale()
Sets the y-scale to be the default (between 0.0 and 1.0).
-
setXscale
public void setXscale(double min, double max)
Sets the x-scale.- 参数:
min
- the minimum value of the x-scalemax
- the maximum value of the x-scale- 抛出:
java.lang.IllegalArgumentException
- if(max == min)
java.lang.IllegalArgumentException
- if eithermin
ormax
is either NaN or infinite
-
setYscale
public void setYscale(double min, double max)
Sets the y-scale.- 参数:
min
- the minimum value of the y-scalemax
- the maximum value of the y-scale- 抛出:
java.lang.IllegalArgumentException
- if(max == min)
java.lang.IllegalArgumentException
- if eithermin
ormax
is either NaN or infinite
-
clear
public void clear()
Clears the screen to the default color (white).
-
clear
public void clear(java.awt.Color color)
Clears the screen to the given color.- 参数:
color
- the color to make the background- 抛出:
java.lang.IllegalArgumentException
- ifcolor
isnull
-
getPenRadius
public double getPenRadius()
Gets the current pen radius.- 返回:
- the current pen radius
-
setPenRadius
public void setPenRadius()
Sets the pen size to the default (.002).
-
setPenRadius
public void setPenRadius(double radius)
Sets the radius of the pen to the given size.- 参数:
radius
- the radius of the pen- 抛出:
java.lang.IllegalArgumentException
- ifradius
is negative, NaN, or infinite
-
getPenColor
public java.awt.Color getPenColor()
Gets the current pen color.- 返回:
- the current pen color
-
setPenColor
public void setPenColor()
Sets the pen color to the default color (black).
-
setPenColor
public void setPenColor(java.awt.Color color)
Sets the pen color to the given color.- 参数:
color
- the color to make the pen- 抛出:
java.lang.IllegalArgumentException
- ifcolor
isnull
-
setPenColor
public void setPenColor(int red, int green, int blue)
Sets the pen color to the given RGB color.- 参数:
red
- the amount of red (between 0 and 255)green
- the amount of green (between 0 and 255)blue
- the amount of blue (between 0 and 255)- 抛出:
java.lang.IllegalArgumentException
- ifred
,green
, orblue
is outside its prescribed range
-
xorOn
public void xorOn()
Turns on xor mode.
-
xorOff
public void xorOff()
Turns off xor mode.
-
getJLabel
public javax.swing.JLabel getJLabel()
Gets the currentJLabel
for use in some other GUI.- 返回:
- the current
JLabel
-
getFont
public java.awt.Font getFont()
Gets the current font.- 返回:
- the current font
-
setFont
public void setFont()
Sets the font to the default font (sans serif, 16 point).
-
setFont
public void setFont(java.awt.Font font)
Sets the font to the given value.- 参数:
font
- the font- 抛出:
java.lang.IllegalArgumentException
- iffont
isnull
-
line
public void line(double x0, double y0, double x1, double y1)
Draws a line from (x0, y0) to (x1, y1).- 参数:
x0
- the x-coordinate of the starting pointy0
- the y-coordinate of the starting pointx1
- the x-coordinate of the destination pointy1
- the y-coordinate of the destination point- 抛出:
java.lang.IllegalArgumentException
- if any coordinate is either NaN or infinite
-
point
public void point(double x, double y)
Draws a point at (x, y).- 参数:
x
- the x-coordinate of the pointy
- the y-coordinate of the point- 抛出:
java.lang.IllegalArgumentException
- if eitherx
ory
is either NaN or infinite
-
circle
public void circle(double x, double y, double radius)
Draws a circle of the specified radius, centered at (x, y).- 参数:
x
- the x-coordinate of the center of the circley
- the y-coordinate of the center of the circleradius
- the radius of the circle- 抛出:
java.lang.IllegalArgumentException
- ifradius
is negativejava.lang.IllegalArgumentException
- if any argument is either NaN or infinite
-
filledCircle
public void filledCircle(double x, double y, double radius)
Draws a filled circle of the specified radius, centered at (x, y).- 参数:
x
- the x-coordinate of the center of the circley
- the y-coordinate of the center of the circleradius
- the radius of the circle- 抛出:
java.lang.IllegalArgumentException
- ifradius
is negativejava.lang.IllegalArgumentException
- if any argument is either NaN or infinite
-
ellipse
public void ellipse(double x, double y, double semiMajorAxis, double semiMinorAxis)
Draws an ellipse with the specified semimajor and semiminor axes, centered at (x, y).- 参数:
x
- the x-coordinate of the center of the ellipsey
- the y-coordinate of the center of the ellipsesemiMajorAxis
- is the semimajor axis of the ellipsesemiMinorAxis
- is the semiminor axis of the ellipse- 抛出:
java.lang.IllegalArgumentException
- if eithersemiMajorAxis
orsemiMinorAxis
is negativejava.lang.IllegalArgumentException
- if any argument is either NaN or infinite
-
filledEllipse
public void filledEllipse(double x, double y, double semiMajorAxis, double semiMinorAxis)
Draws a filled ellipse with the specified semimajor and semiminor axes, centered at (x, y).- 参数:
x
- the x-coordinate of the center of the ellipsey
- the y-coordinate of the center of the ellipsesemiMajorAxis
- is the semimajor axis of the ellipsesemiMinorAxis
- is the semiminor axis of the ellipse- 抛出:
java.lang.IllegalArgumentException
- if eithersemiMajorAxis
orsemiMinorAxis
is negativejava.lang.IllegalArgumentException
- if any argument is either NaN or infinite
-
arc
public void arc(double x, double y, double radius, double angle1, double angle2)
Draws a circular arc of the specified radius, centered at (x, y), from angle1 to angle2 (in degrees).- 参数:
x
- the x-coordinate of the center of the circley
- the y-coordinate of the center of the circleradius
- the radius of the circleangle1
- the starting angle. 0 would mean an arc beginning at 3 o'clock.angle2
- the angle at the end of the arc. For example, if you want a 90 degree arc, then angle2 should be angle1 + 90.- 抛出:
java.lang.IllegalArgumentException
- ifradius
is negativejava.lang.IllegalArgumentException
- if any argument is either NaN or infinite
-
square
public void square(double x, double y, double halfLength)
Draws a square of the specified size, centered at (x, y).- 参数:
x
- the x-coordinate of the center of the squarey
- the y-coordinate of the center of the squarehalfLength
- one half the length of any side of the square- 抛出:
java.lang.IllegalArgumentException
- ifhalfLength
is negativejava.lang.IllegalArgumentException
- if any argument is either NaN or infinite
-
filledSquare
public void filledSquare(double x, double y, double halfLength)
Draws a square of the specified size, centered at (x, y).- 参数:
x
- the x-coordinate of the center of the squarey
- the y-coordinate of the center of the squarehalfLength
- one half the length of any side of the square- 抛出:
java.lang.IllegalArgumentException
- ifhalfLength
is negativejava.lang.IllegalArgumentException
- if any argument is either NaN or infinite
-
rectangle
public void rectangle(double x, double y, double halfWidth, double halfHeight)
Draws a rectangle of the specified size, centered at (x, y).- 参数:
x
- the x-coordinate of the center of the rectangley
- the y-coordinate of the center of the rectanglehalfWidth
- one half the width of the rectanglehalfHeight
- one half the height of the rectangle- 抛出:
java.lang.IllegalArgumentException
- if eitherhalfWidth
orhalfHeight
is negativejava.lang.IllegalArgumentException
- if any argument is either NaN or infinite
-
filledRectangle
public void filledRectangle(double x, double y, double halfWidth, double halfHeight)
Draws a filled rectangle of the specified size, centered at (x, y).- 参数:
x
- the x-coordinate of the center of the rectangley
- the y-coordinate of the center of the rectanglehalfWidth
- one half the width of the rectanglehalfHeight
- one half the height of the rectangle- 抛出:
java.lang.IllegalArgumentException
- if eitherhalfWidth
orhalfHeight
is negativejava.lang.IllegalArgumentException
- if any argument is either NaN or infinite
-
polygon
public void polygon(double[] x, double[] y)
Draws a polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).- 参数:
x
- an array of all the x-coordinates of the polygony
- an array of all the y-coordinates of the polygon- 抛出:
java.lang.IllegalArgumentException
- unlessx[]
andy[]
are of the same lengthjava.lang.IllegalArgumentException
- if any coordinate is either NaN or infinitejava.lang.IllegalArgumentException
- if eitherx[]
ory[]
isnull
-
filledPolygon
public void filledPolygon(double[] x, double[] y)
Draws a filled polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).- 参数:
x
- an array of all the x-coordinates of the polygony
- an array of all the y-coordinates of the polygon- 抛出:
java.lang.IllegalArgumentException
- unlessx[]
andy[]
are of the same lengthjava.lang.IllegalArgumentException
- if any coordinate is either NaN or infinitejava.lang.IllegalArgumentException
- if eitherx[]
ory[]
isnull
-
picture
public void picture(double x, double y, java.lang.String filename)
Draws the specified image centered at (x, y). The supported image formats are JPEG, PNG, and GIF. As an optimization, the picture is cached, so there is no performance penalty for redrawing the same image multiple times (e.g., in an animation). However, if you change the picture file after drawing it, subsequent calls will draw the original picture.- 参数:
x
- the center x-coordinate of the imagey
- the center y-coordinate of the imagefilename
- the name of the image/picture, e.g., "ball.gif"- 抛出:
java.lang.IllegalArgumentException
- if the image filename is invalidjava.lang.IllegalArgumentException
- if eitherx
ory
is either NaN or infinite
-
picture
public void picture(double x, double y, java.lang.String filename, double degrees)
Draws the specified image centered at (x, y), rotated given number of degrees. The supported image formats are JPEG, PNG, and GIF.- 参数:
x
- the center x-coordinate of the imagey
- the center y-coordinate of the imagefilename
- the name of the image/picture, e.g., "ball.gif"degrees
- is the number of degrees to rotate counterclockwise- 抛出:
java.lang.IllegalArgumentException
- if the image filename is invalidjava.lang.IllegalArgumentException
- ifx
,y
,degrees
is NaN or infinitejava.lang.IllegalArgumentException
- iffilename
isnull
-
picture
public void picture(double x, double y, java.lang.String filename, double scaledWidth, double scaledHeight)
Draws the specified image centered at (x, y), rescaled to the specified bounding box. The supported image formats are JPEG, PNG, and GIF.- 参数:
x
- the center x-coordinate of the imagey
- the center y-coordinate of the imagefilename
- the name of the image/picture, e.g., "ball.gif"scaledWidth
- the width of the scaled image (in screen coordinates)scaledHeight
- the height of the scaled image (in screen coordinates)- 抛出:
java.lang.IllegalArgumentException
- if eitherscaledWidth
orscaledHeight
is negativejava.lang.IllegalArgumentException
- if the image filename is invalidjava.lang.IllegalArgumentException
- ifx
ory
is either NaN or infinitejava.lang.IllegalArgumentException
- iffilename
isnull
-
picture
public void picture(double x, double y, java.lang.String filename, double scaledWidth, double scaledHeight, double degrees)
Draws the specified image centered at (x, y), rotated given number of degrees, and rescaled to the specified bounding box. The supported image formats are JPEG, PNG, and GIF.- 参数:
x
- the center x-coordinate of the imagey
- the center y-coordinate of the imagefilename
- the name of the image/picture, e.g., "ball.gif"scaledWidth
- the width of the scaled image (in screen coordinates)scaledHeight
- the height of the scaled image (in screen coordinates)degrees
- is the number of degrees to rotate counterclockwise- 抛出:
java.lang.IllegalArgumentException
- if eitherscaledWidth
orscaledHeight
is negativejava.lang.IllegalArgumentException
- if the image filename is invalid
-
text
public void text(double x, double y, java.lang.String text)
Writes the given text string in the current font, centered at (x, y).- 参数:
x
- the center x-coordinate of the texty
- the center y-coordinate of the texttext
- the text to write- 抛出:
java.lang.IllegalArgumentException
- iftext
isnull
java.lang.IllegalArgumentException
- ifx
ory
is either NaN or infinite
-
text
public void text(double x, double y, java.lang.String text, double degrees)
Writes the given text string in the current font, centered at (x, y) and rotated by the specified number of degrees.- 参数:
x
- the center x-coordinate of the texty
- the center y-coordinate of the texttext
- the text to writedegrees
- is the number of degrees to rotate counterclockwise- 抛出:
java.lang.IllegalArgumentException
- iftext
isnull
java.lang.IllegalArgumentException
- ifx
,y
, ordegrees
is either NaN or infinite
-
textLeft
public void textLeft(double x, double y, java.lang.String text)
Writes the given text string in the current font, left-aligned at (x, y).- 参数:
x
- the x-coordinate of the texty
- the y-coordinate of the texttext
- the text- 抛出:
java.lang.IllegalArgumentException
- iftext
isnull
java.lang.IllegalArgumentException
- ifx
ory
is either NaN or infinite
-
textRight
public void textRight(double x, double y, java.lang.String text)
Writes the given text string in the current font, right-aligned at (x, y).- 参数:
x
- the x-coordinate of the texty
- the y-coordinate of the texttext
- the text to write- 抛出:
java.lang.IllegalArgumentException
- iftext
isnull
java.lang.IllegalArgumentException
- ifx
ory
is either NaN or infinite
-
show
@Deprecated public void show(int t)
已过时。Copies the offscreen buffer to the onscreen buffer, pauses for t milliseconds and enables double buffering.- 参数:
t
- number of milliseconds
-
pause
public void pause(int t)
Pause for t milliseconds. This method is intended to support computer animations.- 参数:
t
- number of milliseconds
-
show
public void show()
Copies offscreen buffer to onscreen buffer. There is no reason to call this method unless double buffering is enabled.
-
enableDoubleBuffering
public void enableDoubleBuffering()
Enable double buffering. All subsequent calls to drawing methods such asline()
,circle()
, andsquare()
will be deferred until the next call to show(). Useful for animations.
-
disableDoubleBuffering
public void disableDoubleBuffering()
Disable double buffering. All subsequent calls to drawing methods such asline()
,circle()
, andsquare()
will be displayed on screen when called. This is the default.
-
save
public void save(java.lang.String filename)
Saves the drawing to using the specified filename. The supported image formats are JPEG and PNG; the filename suffix must be.jpg
or.png
.- 参数:
filename
- the name of the file with one of the required suffixes- 抛出:
java.lang.IllegalArgumentException
- iffilename
isnull
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
This method cannot be called directly.- 指定者:
actionPerformed
在接口中java.awt.event.ActionListener
-
addListener
public void addListener(DrawListener listener)
Adds aDrawListener
to listen to keyboard and mouse events.- 参数:
listener
- the {\tt DrawListener} argument
-
isMousePressed
public boolean isMousePressed()
Returns true if the mouse is being pressed.- 返回:
true
if the mouse is being pressed;false
otherwise
-
mousePressed
@Deprecated public boolean mousePressed()
已过时。replaced byisMousePressed()
Returns true if the mouse is being pressed.- 返回:
true
if the mouse is being pressed;false
otherwise
-
mouseX
public double mouseX()
Returns the x-coordinate of the mouse.- 返回:
- the x-coordinate of the mouse
-
mouseY
public double mouseY()
Returns the y-coordinate of the mouse.- 返回:
- the y-coordinate of the mouse
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)
This method cannot be called directly.- 指定者:
mouseEntered
在接口中java.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
This method cannot be called directly.- 指定者:
mouseExited
在接口中java.awt.event.MouseListener
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
This method cannot be called directly.- 指定者:
mousePressed
在接口中java.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
This method cannot be called directly.- 指定者:
mouseReleased
在接口中java.awt.event.MouseListener
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)
This method cannot be called directly.- 指定者:
mouseClicked
在接口中java.awt.event.MouseListener
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
This method cannot be called directly.- 指定者:
mouseDragged
在接口中java.awt.event.MouseMotionListener
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
This method cannot be called directly.- 指定者:
mouseMoved
在接口中java.awt.event.MouseMotionListener
-
hasNextKeyTyped
public boolean hasNextKeyTyped()
Returns true if the user has typed a key.- 返回:
true
if the user has typed a key;false
otherwise
-
nextKeyTyped
public char nextKeyTyped()
The next key typed by the user.- 返回:
- the next key typed by the user
-
isKeyPressed
public boolean isKeyPressed(int keycode)
Returns true if the keycode is being pressed.This method takes as an argument the keycode (corresponding to a physical key). It can handle action keys (such as F1 and arrow keys) and modifier keys (such as shift and control). See
KeyEvent
for a description of key codes.- 参数:
keycode
- the keycode to check- 返回:
true
ifkeycode
is currently being pressed;false
otherwise
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent e)
This method cannot be called directly.- 指定者:
keyTyped
在接口中java.awt.event.KeyListener
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent e)
This method cannot be called directly.- 指定者:
keyPressed
在接口中java.awt.event.KeyListener
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent e)
This method cannot be called directly.- 指定者:
keyReleased
在接口中java.awt.event.KeyListener
-
main
public static void main(java.lang.String[] args)
Test client.- 参数:
args
- the command-line arguments
-
-