类 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.KeyListenerDraw. 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.ColorBLACKThe color black.static java.awt.ColorBLUEThe color blue.static java.awt.ColorBOOK_BLUEShade of blue used in Introduction to Programming in Java.static java.awt.ColorBOOK_LIGHT_BLUEShade of light blue used in Introduction to Programming in Java.static java.awt.ColorBOOK_REDShade of red used in Algorithms, 4th edition.static java.awt.ColorCYANThe color cyan.static java.awt.ColorDARK_GRAYThe color dark gray.static java.awt.ColorGRAYThe color gray.static java.awt.ColorGREENThe color green.static java.awt.ColorLIGHT_GRAYThe color light gray.static java.awt.ColorMAGENTAThe color magenta.static java.awt.ColorORANGEThe color orange.static java.awt.ColorPINKThe color pink.static java.awt.ColorPRINCETON_ORANGEShade of orange used in Princeton's identity.static java.awt.ColorREDThe color red.static java.awt.ColorWHITEThe color white.static java.awt.ColorYELLOWThe color yellow.
 - 
方法概要修饰符和类型 方法 说明 voidactionPerformed(java.awt.event.ActionEvent e)This method cannot be called directly.voidaddListener(DrawListener listener)Adds aDrawListenerto listen to keyboard and mouse events.voidarc(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).voidcircle(double x, double y, double radius)Draws a circle of the specified radius, centered at (x, y).voidclear()Clears the screen to the default color (white).voidclear(java.awt.Color color)Clears the screen to the given color.voiddisableDoubleBuffering()Disable double buffering.voidellipse(double x, double y, double semiMajorAxis, double semiMinorAxis)Draws an ellipse with the specified semimajor and semiminor axes, centered at (x, y).voidenableDoubleBuffering()Enable double buffering.voidfilledCircle(double x, double y, double radius)Draws a filled circle of the specified radius, centered at (x, y).voidfilledEllipse(double x, double y, double semiMajorAxis, double semiMinorAxis)Draws a filled ellipse with the specified semimajor and semiminor axes, centered at (x, y).voidfilledPolygon(double[] x, double[] y)Draws a filled polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).voidfilledRectangle(double x, double y, double halfWidth, double halfHeight)Draws a filled rectangle of the specified size, centered at (x, y).voidfilledSquare(double x, double y, double halfLength)Draws a square of the specified size, centered at (x, y).java.awt.FontgetFont()Gets the current font.javax.swing.JLabelgetJLabel()Gets the currentJLabelfor use in some other GUI.java.awt.ColorgetPenColor()Gets the current pen color.doublegetPenRadius()Gets the current pen radius.booleanhasNextKeyTyped()Returns true if the user has typed a key.booleanisKeyPressed(int keycode)Returns true if the keycode is being pressed.booleanisMousePressed()Returns true if the mouse is being pressed.voidkeyPressed(java.awt.event.KeyEvent e)This method cannot be called directly.voidkeyReleased(java.awt.event.KeyEvent e)This method cannot be called directly.voidkeyTyped(java.awt.event.KeyEvent e)This method cannot be called directly.voidline(double x0, double y0, double x1, double y1)Draws a line from (x0, y0) to (x1, y1).static voidmain(java.lang.String[] args)Test client.voidmouseClicked(java.awt.event.MouseEvent e)This method cannot be called directly.voidmouseDragged(java.awt.event.MouseEvent e)This method cannot be called directly.voidmouseEntered(java.awt.event.MouseEvent e)This method cannot be called directly.voidmouseExited(java.awt.event.MouseEvent e)This method cannot be called directly.voidmouseMoved(java.awt.event.MouseEvent e)This method cannot be called directly.booleanmousePressed()已过时。replaced byisMousePressed()voidmousePressed(java.awt.event.MouseEvent e)This method cannot be called directly.voidmouseReleased(java.awt.event.MouseEvent e)This method cannot be called directly.doublemouseX()Returns the x-coordinate of the mouse.doublemouseY()Returns the y-coordinate of the mouse.charnextKeyTyped()The next key typed by the user.voidpause(int t)Pause for t milliseconds.voidpicture(double x, double y, java.lang.String filename)Draws the specified image centered at (x, y).voidpicture(double x, double y, java.lang.String filename, double degrees)Draws the specified image centered at (x, y), rotated given number of degrees.voidpicture(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.voidpicture(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.voidpoint(double x, double y)Draws a point at (x, y).voidpolygon(double[] x, double[] y)Draws a polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).voidrectangle(double x, double y, double halfWidth, double halfHeight)Draws a rectangle of the specified size, centered at (x, y).voidsave(java.lang.String filename)Saves the drawing to using the specified filename.voidsetCanvasSize(int canvasWidth, int canvasHeight)Sets the canvas (drawing area) to be width-by-height pixels.voidsetDefaultCloseOperation(int value)Sets the default close operation.voidsetFont()Sets the font to the default font (sans serif, 16 point).voidsetFont(java.awt.Font font)Sets the font to the given value.voidsetLocationOnScreen(int x, int y)Sets the upper-left hand corner of the drawing window to be (x, y), where (0, 0) is upper left.voidsetPenColor()Sets the pen color to the default color (black).voidsetPenColor(int red, int green, int blue)Sets the pen color to the given RGB color.voidsetPenColor(java.awt.Color color)Sets the pen color to the given color.voidsetPenRadius()Sets the pen size to the default (.002).voidsetPenRadius(double radius)Sets the radius of the pen to the given size.voidsetXscale()Sets the x-scale to be the default (between 0.0 and 1.0).voidsetXscale(double min, double max)Sets the x-scale.voidsetYscale()Sets the y-scale to be the default (between 0.0 and 1.0).voidsetYscale(double min, double max)Sets the y-scale.voidshow()Copies offscreen buffer to onscreen buffer.voidshow(int t)已过时。voidsquare(double x, double y, double halfLength)Draws a square of the specified size, centered at (x, y).voidtext(double x, double y, java.lang.String text)Writes the given text string in the current font, centered at (x, y).voidtext(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.voidtextLeft(double x, double y, java.lang.String text)Writes the given text string in the current font, left-aligned at (x, y).voidtextRight(double x, double y, java.lang.String text)Writes the given text string in the current font, right-aligned at (x, y).voidxorOff()Turns off xor mode.voidxorOn()Turns on xor mode.
 
- 
- 
- 
字段详细资料- 
BLACKpublic static final java.awt.Color BLACK The color black.
 - 
BLUEpublic static final java.awt.Color BLUE The color blue.
 - 
CYANpublic static final java.awt.Color CYAN The color cyan.
 - 
DARK_GRAYpublic static final java.awt.Color DARK_GRAY The color dark gray.
 - 
GRAYpublic static final java.awt.Color GRAY The color gray.
 - 
GREENpublic static final java.awt.Color GREEN The color green.
 - 
LIGHT_GRAYpublic static final java.awt.Color LIGHT_GRAY The color light gray.
 - 
MAGENTApublic static final java.awt.Color MAGENTA The color magenta.
 - 
ORANGEpublic static final java.awt.Color ORANGE The color orange.
 - 
PINKpublic static final java.awt.Color PINK The color pink.
 - 
REDpublic static final java.awt.Color RED The color red.
 - 
WHITEpublic static final java.awt.Color WHITE The color white.
 - 
YELLOWpublic static final java.awt.Color YELLOW The color yellow.
 - 
BOOK_BLUEpublic 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_BLUEpublic 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_REDpublic 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_ORANGEpublic 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).
 
- 
 - 
方法详细资料- 
setLocationOnScreenpublic 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 left
- y- the number of pixels from the top
- 抛出:
- java.lang.IllegalArgumentException- if the width or height is 0 or negative
 
 - 
setDefaultCloseOperationpublic void setDefaultCloseOperation(int value) Sets the default close operation.- 参数:
- value- the value, typically- JFrame.EXIT_ON_CLOSE(close all windows) or- JFrame.DISPOSE_ON_CLOSE(close current window)
 
 - 
setCanvasSizepublic 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 pixels
- canvasHeight- the height as a number of pixels
- 抛出:
- java.lang.IllegalArgumentException- unless both- canvasWidthand- canvasHeightare positive
 
 - 
setXscalepublic void setXscale() Sets the x-scale to be the default (between 0.0 and 1.0).
 - 
setYscalepublic void setYscale() Sets the y-scale to be the default (between 0.0 and 1.0).
 - 
setXscalepublic void setXscale(double min, double max)Sets the x-scale.- 参数:
- min- the minimum value of the x-scale
- max- the maximum value of the x-scale
- 抛出:
- java.lang.IllegalArgumentException- if- (max == min)
- java.lang.IllegalArgumentException- if either- minor- maxis either NaN or infinite
 
 - 
setYscalepublic void setYscale(double min, double max)Sets the y-scale.- 参数:
- min- the minimum value of the y-scale
- max- the maximum value of the y-scale
- 抛出:
- java.lang.IllegalArgumentException- if- (max == min)
- java.lang.IllegalArgumentException- if either- minor- maxis either NaN or infinite
 
 - 
clearpublic void clear() Clears the screen to the default color (white).
 - 
clearpublic void clear(java.awt.Color color) Clears the screen to the given color.- 参数:
- color- the color to make the background
- 抛出:
- java.lang.IllegalArgumentException- if- coloris- null
 
 - 
getPenRadiuspublic double getPenRadius() Gets the current pen radius.- 返回:
- the current pen radius
 
 - 
setPenRadiuspublic void setPenRadius() Sets the pen size to the default (.002).
 - 
setPenRadiuspublic void setPenRadius(double radius) Sets the radius of the pen to the given size.- 参数:
- radius- the radius of the pen
- 抛出:
- java.lang.IllegalArgumentException- if- radiusis negative, NaN, or infinite
 
 - 
getPenColorpublic java.awt.Color getPenColor() Gets the current pen color.- 返回:
- the current pen color
 
 - 
setPenColorpublic void setPenColor() Sets the pen color to the default color (black).
 - 
setPenColorpublic void setPenColor(java.awt.Color color) Sets the pen color to the given color.- 参数:
- color- the color to make the pen
- 抛出:
- java.lang.IllegalArgumentException- if- coloris- null
 
 - 
setPenColorpublic 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- if- red,- green, or- blueis outside its prescribed range
 
 - 
xorOnpublic void xorOn() Turns on xor mode.
 - 
xorOffpublic void xorOff() Turns off xor mode.
 - 
getJLabelpublic javax.swing.JLabel getJLabel() Gets the currentJLabelfor use in some other GUI.- 返回:
- the current JLabel
 
 - 
getFontpublic java.awt.Font getFont() Gets the current font.- 返回:
- the current font
 
 - 
setFontpublic void setFont() Sets the font to the default font (sans serif, 16 point).
 - 
setFontpublic void setFont(java.awt.Font font) Sets the font to the given value.- 参数:
- font- the font
- 抛出:
- java.lang.IllegalArgumentException- if- fontis- null
 
 - 
linepublic 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 point
- y0- the y-coordinate of the starting point
- x1- the x-coordinate of the destination point
- y1- the y-coordinate of the destination point
- 抛出:
- java.lang.IllegalArgumentException- if any coordinate is either NaN or infinite
 
 - 
pointpublic void point(double x, double y)Draws a point at (x, y).- 参数:
- x- the x-coordinate of the point
- y- the y-coordinate of the point
- 抛出:
- java.lang.IllegalArgumentException- if either- xor- yis either NaN or infinite
 
 - 
circlepublic 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 circle
- y- the y-coordinate of the center of the circle
- radius- the radius of the circle
- 抛出:
- java.lang.IllegalArgumentException- if- radiusis negative
- java.lang.IllegalArgumentException- if any argument is either NaN or infinite
 
 - 
filledCirclepublic 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 circle
- y- the y-coordinate of the center of the circle
- radius- the radius of the circle
- 抛出:
- java.lang.IllegalArgumentException- if- radiusis negative
- java.lang.IllegalArgumentException- if any argument is either NaN or infinite
 
 - 
ellipsepublic 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 ellipse
- y- the y-coordinate of the center of the ellipse
- semiMajorAxis- is the semimajor axis of the ellipse
- semiMinorAxis- is the semiminor axis of the ellipse
- 抛出:
- java.lang.IllegalArgumentException- if either- semiMajorAxisor- semiMinorAxisis negative
- java.lang.IllegalArgumentException- if any argument is either NaN or infinite
 
 - 
filledEllipsepublic 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 ellipse
- y- the y-coordinate of the center of the ellipse
- semiMajorAxis- is the semimajor axis of the ellipse
- semiMinorAxis- is the semiminor axis of the ellipse
- 抛出:
- java.lang.IllegalArgumentException- if either- semiMajorAxisor- semiMinorAxisis negative
- java.lang.IllegalArgumentException- if any argument is either NaN or infinite
 
 - 
arcpublic 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 circle
- y- the y-coordinate of the center of the circle
- radius- the radius of the circle
- angle1- 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- if- radiusis negative
- java.lang.IllegalArgumentException- if any argument is either NaN or infinite
 
 - 
squarepublic 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 square
- y- the y-coordinate of the center of the square
- halfLength- one half the length of any side of the square
- 抛出:
- java.lang.IllegalArgumentException- if- halfLengthis negative
- java.lang.IllegalArgumentException- if any argument is either NaN or infinite
 
 - 
filledSquarepublic 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 square
- y- the y-coordinate of the center of the square
- halfLength- one half the length of any side of the square
- 抛出:
- java.lang.IllegalArgumentException- if- halfLengthis negative
- java.lang.IllegalArgumentException- if any argument is either NaN or infinite
 
 - 
rectanglepublic 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 rectangle
- y- the y-coordinate of the center of the rectangle
- halfWidth- one half the width of the rectangle
- halfHeight- one half the height of the rectangle
- 抛出:
- java.lang.IllegalArgumentException- if either- halfWidthor- halfHeightis negative
- java.lang.IllegalArgumentException- if any argument is either NaN or infinite
 
 - 
filledRectanglepublic 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 rectangle
- y- the y-coordinate of the center of the rectangle
- halfWidth- one half the width of the rectangle
- halfHeight- one half the height of the rectangle
- 抛出:
- java.lang.IllegalArgumentException- if either- halfWidthor- halfHeightis negative
- java.lang.IllegalArgumentException- if any argument is either NaN or infinite
 
 - 
polygonpublic 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 polygon
- y- an array of all the y-coordinates of the polygon
- 抛出:
- java.lang.IllegalArgumentException- unless- x[]and- y[]are of the same length
- java.lang.IllegalArgumentException- if any coordinate is either NaN or infinite
- java.lang.IllegalArgumentException- if either- x[]or- y[]is- null
 
 - 
filledPolygonpublic 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 polygon
- y- an array of all the y-coordinates of the polygon
- 抛出:
- java.lang.IllegalArgumentException- unless- x[]and- y[]are of the same length
- java.lang.IllegalArgumentException- if any coordinate is either NaN or infinite
- java.lang.IllegalArgumentException- if either- x[]or- y[]is- null
 
 - 
picturepublic 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 image
- y- the center y-coordinate of the image
- filename- the name of the image/picture, e.g., "ball.gif"
- 抛出:
- java.lang.IllegalArgumentException- if the image filename is invalid
- java.lang.IllegalArgumentException- if either- xor- yis either NaN or infinite
 
 - 
picturepublic 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 image
- y- the center y-coordinate of the image
- filename- 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 invalid
- java.lang.IllegalArgumentException- if- x,- y,- degreesis NaN or infinite
- java.lang.IllegalArgumentException- if- filenameis- null
 
 - 
picturepublic 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 image
- y- the center y-coordinate of the image
- filename- 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 either- scaledWidthor- scaledHeightis negative
- java.lang.IllegalArgumentException- if the image filename is invalid
- java.lang.IllegalArgumentException- if- xor- yis either NaN or infinite
- java.lang.IllegalArgumentException- if- filenameis- null
 
 - 
picturepublic 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 image
- y- the center y-coordinate of the image
- filename- 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 either- scaledWidthor- scaledHeightis negative
- java.lang.IllegalArgumentException- if the image filename is invalid
 
 - 
textpublic 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 text
- y- the center y-coordinate of the text
- text- the text to write
- 抛出:
- java.lang.IllegalArgumentException- if- textis- null
- java.lang.IllegalArgumentException- if- xor- yis either NaN or infinite
 
 - 
textpublic 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 text
- y- the center y-coordinate of the text
- text- the text to write
- degrees- is the number of degrees to rotate counterclockwise
- 抛出:
- java.lang.IllegalArgumentException- if- textis- null
- java.lang.IllegalArgumentException- if- x,- y, or- degreesis either NaN or infinite
 
 - 
textLeftpublic 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 text
- y- the y-coordinate of the text
- text- the text
- 抛出:
- java.lang.IllegalArgumentException- if- textis- null
- java.lang.IllegalArgumentException- if- xor- yis either NaN or infinite
 
 - 
textRightpublic 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 text
- y- the y-coordinate of the text
- text- the text to write
- 抛出:
- java.lang.IllegalArgumentException- if- textis- null
- java.lang.IllegalArgumentException- if- xor- yis 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
 
 - 
pausepublic void pause(int t) Pause for t milliseconds. This method is intended to support computer animations.- 参数:
- t- number of milliseconds
 
 - 
showpublic void show() Copies offscreen buffer to onscreen buffer. There is no reason to call this method unless double buffering is enabled.
 - 
enableDoubleBufferingpublic 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.
 - 
disableDoubleBufferingpublic 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.
 - 
savepublic 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.jpgor.png.- 参数:
- filename- the name of the file with one of the required suffixes
- 抛出:
- java.lang.IllegalArgumentException- if- filenameis- null
 
 - 
actionPerformedpublic void actionPerformed(java.awt.event.ActionEvent e) This method cannot be called directly.- 指定者:
- actionPerformed在接口中- java.awt.event.ActionListener
 
 - 
addListenerpublic void addListener(DrawListener listener) Adds aDrawListenerto listen to keyboard and mouse events.- 参数:
- listener- the {\tt DrawListener} argument
 
 - 
isMousePressedpublic boolean isMousePressed() Returns true if the mouse is being pressed.- 返回:
- trueif the mouse is being pressed;- falseotherwise
 
 - 
mousePressed@Deprecated public boolean mousePressed() 已过时。replaced byisMousePressed()Returns true if the mouse is being pressed.- 返回:
- trueif the mouse is being pressed;- falseotherwise
 
 - 
mouseXpublic double mouseX() Returns the x-coordinate of the mouse.- 返回:
- the x-coordinate of the mouse
 
 - 
mouseYpublic double mouseY() Returns the y-coordinate of the mouse.- 返回:
- the y-coordinate of the mouse
 
 - 
mouseEnteredpublic void mouseEntered(java.awt.event.MouseEvent e) This method cannot be called directly.- 指定者:
- mouseEntered在接口中- java.awt.event.MouseListener
 
 - 
mouseExitedpublic void mouseExited(java.awt.event.MouseEvent e) This method cannot be called directly.- 指定者:
- mouseExited在接口中- java.awt.event.MouseListener
 
 - 
mousePressedpublic void mousePressed(java.awt.event.MouseEvent e) This method cannot be called directly.- 指定者:
- mousePressed在接口中- java.awt.event.MouseListener
 
 - 
mouseReleasedpublic void mouseReleased(java.awt.event.MouseEvent e) This method cannot be called directly.- 指定者:
- mouseReleased在接口中- java.awt.event.MouseListener
 
 - 
mouseClickedpublic void mouseClicked(java.awt.event.MouseEvent e) This method cannot be called directly.- 指定者:
- mouseClicked在接口中- java.awt.event.MouseListener
 
 - 
mouseDraggedpublic void mouseDragged(java.awt.event.MouseEvent e) This method cannot be called directly.- 指定者:
- mouseDragged在接口中- java.awt.event.MouseMotionListener
 
 - 
mouseMovedpublic void mouseMoved(java.awt.event.MouseEvent e) This method cannot be called directly.- 指定者:
- mouseMoved在接口中- java.awt.event.MouseMotionListener
 
 - 
hasNextKeyTypedpublic boolean hasNextKeyTyped() Returns true if the user has typed a key.- 返回:
- trueif the user has typed a key;- falseotherwise
 
 - 
nextKeyTypedpublic char nextKeyTyped() The next key typed by the user.- 返回:
- the next key typed by the user
 
 - 
isKeyPressedpublic 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 KeyEventfor a description of key codes.- 参数:
- keycode- the keycode to check
- 返回:
- trueif- keycodeis currently being pressed;- falseotherwise
 
 - 
keyTypedpublic void keyTyped(java.awt.event.KeyEvent e) This method cannot be called directly.- 指定者:
- keyTyped在接口中- java.awt.event.KeyListener
 
 - 
keyPressedpublic void keyPressed(java.awt.event.KeyEvent e) This method cannot be called directly.- 指定者:
- keyPressed在接口中- java.awt.event.KeyListener
 
 - 
keyReleasedpublic void keyReleased(java.awt.event.KeyEvent e) This method cannot be called directly.- 指定者:
- keyReleased在接口中- java.awt.event.KeyListener
 
 - 
mainpublic static void main(java.lang.String[] args) Test client.- 参数:
- args- the command-line arguments
 
 
- 
 
-