Class StdDraw 类 StdDraw
- Object 对象
-
- StdDraw
-
- All Implemented Interfaces:
所有实现的接口: ActionListener
,KeyListener
,MouseListener
,MouseMotionListener
,EventListener
public final class StdDraw extends Object implements ActionListener, MouseListener, MouseMotionListener, KeyListener
TheStdDraw
class provides static methods for creating drawings with your programs. It uses a simple graphics model that allows you to create drawings consisting of points, lines, squares, circles, and other geometric shapes in a window on your computer and to save the drawings to a file.
StdDraw
类提供了用于创建程序图形的静态方法。它使用一种简单的图形模型,允许您在计算机窗口中创建由点、线、方块、圆形和其他几何形状组成的图形,并将图形保存到文件中。
Standard drawing also includes facilities for text, color, pictures, and animation, along with user interaction via the keyboard and mouse.
标准绘图还包括文本、颜色、图片和动画等功能,以及通过键盘和鼠标进行用户交互。Getting started. To use this class, you must have
StdDraw.class
in your Java classpath. If you used our autoinstaller, you should be all set. Otherwise, either download stdlib.jar and add to your Java classpath or download StdDraw.java and put a copy in your working directory.
开始。要使用这个类,你必须在你的 Java 类路径中有StdDraw.class
。如果你使用了我们的自动安装程序,你应该已经准备就绪了。否则,要么下载 stdlib.jar 并添加到你的 Java 类路径中,要么下载 StdDraw.java 并将副本放入你的工作目录。Now, cut-and-paste the following short program into your editor:
现在,将以下简短程序剪切粘贴到您的编辑器中:public class TestStdDraw { public static void main(String[] args) { StdDraw.setPenRadius(0.05); StdDraw.setPenColor(StdDraw.BLUE); StdDraw.point(0.5, 0.5); StdDraw.setPenColor(StdDraw.MAGENTA); StdDraw.line(0.2, 0.2, 0.8, 0.2); } }
If you compile and execute the program, you should see a window appear with a thick magenta line and a blue point. This program illustrates the two main types of methods in standard drawing—methods that draw geometric shapes and methods that control drawing parameters.
如果您编译并执行该程序,您应该会看到一个窗口出现,里面有一条粗厚的品红色线条和一个蓝色点。这个程序展示了标准绘图中的两种主要方法——绘制几何图形的方法和控制绘图参数的方法。
The methodsStdDraw.line()
andStdDraw.point()
draw lines and points; the methodsStdDraw.setPenRadius()
andStdDraw.setPenColor()
control the line thickness and color.
方法StdDraw.line()
和StdDraw.point()
绘制线条和点;方法StdDraw.setPenRadius()
和StdDraw.setPenColor()
控制线条的粗细和颜色。Points and lines. You can draw points and line segments with the following methods:
点和线。您可以通过以下方法绘制点和线段:The x- and y-coordinates must be in the drawing area (between 0 and 1 and by default) or the points and lines will not be visible.
x 和 y 坐标必须在绘图区域内(默认值为 0 到 1 之间),否则点和线将不可见。Squares, circles, rectangles, and ellipses. You can draw squares, circles, rectangles, and ellipses using the following methods:
正方形、圆形、矩形和椭圆。您可以使用以下方法绘制正方形、圆形、矩形和椭圆:-
circle(double x, double y, double radius)
-
ellipse(double x, double y, double semiMajorAxis, double semiMinorAxis)
-
square(double x, double y, double halfLength)
-
rectangle(double x, double y, double halfWidth, double halfHeight)
All of these methods take as arguments the location and size of the shape. The location is always specified by the x- and y-coordinates of its center. The size of a circle is specified by its radius and the size of an ellipse is specified by the lengths of its semi-major and semi-minor axes. The size of a square or rectangle is specified by its half-width or half-height.
所有这些方法都需要将形状的位置和大小作为参数。位置总是由其中心的 x 和 y 坐标指定。圆的大小由其半径指定,椭圆的大小由其半长轴和半短轴的长度指定。正方形或矩形的大小由其半宽度或半高度指定。
The convention for drawing squares and rectangles is parallel to those for drawing circles and ellipses, but may be unexpected to the uninitiated.
绘制正方形和矩形的惯例与绘制圆和椭圆的惯例平行,但对于未经培训的人来说可能是意想不到的。The methods above trace outlines of the given shapes. The following methods draw filled versions:
以上方法追踪给定形状的轮廓。以下方法绘制填充版本:-
filledCircle(double x, double y, double radius)
-
filledEllipse(double x, double y, double semiMajorAxis, double semiMinorAxis)
-
filledSquare(double x, double y, double radius)
-
filledRectangle(double x, double y, double halfWidth, double halfHeight)
Circular arcs. You can draw circular arcs with the following method:
圆弧。您可以使用以下方法绘制圆弧:The arc is from the circle centered at (x, y) of the specified radius. The arc extends from angle1 to angle2. By convention, the angles are polar (counterclockwise angle from the x-axis) and represented in degrees. For example,
StdDraw.arc(0.0, 0.0, 1.0, 0, 90)
draws the arc of the unit circle from 3 o'clock (0 degrees) to 12 o'clock (90 degrees).
该弧来自于以 (x, y) 为中心、指定半径的圆。该弧从 angle1 延伸到 angle2。根据惯例,角度为极坐标(从 x 轴逆时针测量的角度),以度数表示。例如,StdDraw.arc(0.0, 0.0, 1.0, 0, 90)
绘制从 3 点钟方向(0 度)到 12 点钟方向(90 度)的单位圆弧。Polygons. You can draw polygons with the following methods:
多边形。您可以使用以下方法绘制多边形:The points in the polygon are (
x[i]
,y[i]
). For example, the following code fragment draws a filled diamond with vertices (0.1, 0.2), (0.2, 0.3), (0.3, 0.2), and (0.2, 0.1):
多边形中的点是 (x[i]
,y[i]
)。例如,以下代码片段绘制了一个填充的菱形,顶点为 (0.1, 0.2)、(0.2, 0.3)、(0.3, 0.2) 和 (0.2, 0.1):double[] x = { 0.1, 0.2, 0.3, 0.2 }; double[] y = { 0.2, 0.3, 0.2, 0.1 }; StdDraw.filledPolygon(x, y);
Pen size. The pen is circular, so that when you set the pen radius to r and draw a point, you get a circle of radius r. Also, lines are of thickness 2r and have rounded ends. The default pen radius is 0.002 and is not affected by coordinate scaling.
笔尖大小。笔是圆形的,所以当你将笔的半径设置为 r 并画一个点时,你会得到一个半径为 r 的圆。此外,线条的厚度为 2r,并且两端是圆角的。默认的笔半径为 0.002,并不受坐标缩放的影响。
This default pen radius is about 1/500 the width of the default canvas, so that if you draw 200 points equally spaced along a horizontal or vertical line, you will be able to see individual circles, but if you draw 250 such points, the result will look like a line.
此默认笔径约为默认画布宽度的 1/500,因此如果沿水平或垂直线绘制 200 个等距点,您将能够看到单独的圆圈,但如果绘制 250 个这样的点,结果将看起来像一条线。For example,
StdDraw.setPenRadius(0.01)
makes the thickness of the lines and the size of the points to be five times the 0.002 default. To draw points with the minimum possible radius (one pixel on typical displays), set the pen radius to 0.0.
例如,StdDraw.setPenRadius(0.01)
使线条的粗细和点的大小是默认值 0.002 的五倍。要绘制具有最小可能半径的点(在典型显示器上为一个像素),将笔半径设置为 0.0。Pen color. All geometric shapes (such as points, lines, and circles) are drawn using the current pen color. By default, it is black. You can change the pen color with the following methods:
笔颜色。所有几何形状(例如点、线和圆)都是使用当前的笔颜色绘制的。默认情况下,它是黑色。您可以通过以下方法更改笔颜色:The first method allows you to specify colors using the RGB color system. This color picker is a convenient way to find a desired color.
第一种方法允许您使用 RGB 颜色系统指定颜色。这个颜色选择器是查找所需颜色的便捷方式。The second method allows you to specify colors using the
Color
data type, which is defined in Java'sjava.awt
package. Standard drawing defines a number of predefined colors includingBLACK
,WHITE
,RED
,GREEN
, andBLUE
. For example,StdDraw.setPenColor(StdDraw.RED)
sets the pen color to red.
第二种方法允许您使用在 Java 的`java.awt
`包中定义的`Color
`数据类型来指定颜色。标准绘图定义了许多预定义颜色,包括`BLACK
`,`WHITE
`,`RED
`,`GREEN
`和`BLUE
`。例如,`StdDraw.setPenColor(StdDraw.RED)
`将笔的颜色设置为红色。Window title. By default, the standard drawing window title is "Standard Draw". You can change the title with the following method:
窗口标题。默认情况下,标准绘图窗口标题为“标准绘图”。您可以使用以下方法更改标题:This sets the standard drawing window title to the specified string.
将标准绘图窗口标题设置为指定的字符串。Canvas size. By default, all drawing takes places in a 512-by-512 canvas. The canvas does not include the window title or window border. You can change the size of the canvas with the following method:
画布大小。默认情况下,所有绘图都发生在一个 512x512 的画布上。 画布不包括窗口标题或窗口边框。 您可以使用以下方法更改画布大小:This sets the canvas size to be width-by-height pixels. It also clears the current drawing using the default background color (white). Ordinarily, this method is called only once, at the very beginning of a program. For example,
StdDraw.setCanvasSize(800, 800)
sets the canvas size to be 800-by-800 pixels.
这将画布大小设置为宽度×高度像素。它还使用默认背景颜色(白色)清除当前绘图。通常情况下,此方法仅在程序开始时调用一次。例如,StdDraw.setCanvasSize(800, 800)
将画布大小设置为 800×800 像素。Canvas scale and coordinate system. By default, all drawing takes places in the unit square, with (0, 0) at lower left and (1, 1) at upper right. You can change the default coordinate system with the following methods:
画布比例和坐标系统。默认情况下,所有绘图发生在单位正方形内,左下角为(0, 0),右上角为(1, 1)。您可以使用以下方法更改默认坐标系统:-
setXscale(double xmin, double xmax)
-
setYscale(double ymin, double ymax)
-
setScale(double min, double max)
The arguments are the coordinates of the minimum and maximum x- or y-coordinates that will appear in the canvas. For example, if you wish to use the default coordinate system but leave a small margin, you can call
StdDraw.setScale(-.05, 1.05)
.
参数是画布中将出现的最小和最大 x 或 y 坐标的坐标。例如,如果您希望使用默认坐标系但留下一小部分空白,您可以调用StdDraw.setScale(-.05, 1.05)
。These methods change the coordinate system for subsequent drawing commands; they do not affect previous drawings. These methods do not change the canvas size; so, if the x- and y-scales are different, squares will become rectangles and circles will become ellipses.
这些方法改变后续绘图命令的坐标系统;它们不会影响之前的绘图。这些方法不会改变画布大小;因此,如果 x 轴和 y 轴的比例不同,正方形将变成矩形,圆形将变成椭圆。Text. You can use the following methods to annotate your drawings with text:
文本。您可以使用以下方法为您的图纸添加文本注释:-
text(double x, double y, String text)
-
text(double x, double y, String text, double degrees)
-
textLeft(double x, double y, String text)
-
textRight(double x, double y, String text)
The first two methods write the specified text in the current font, centered at (x, y). The second method allows you to rotate the text. The last two methods either left- or right-align the text at (x, y).
前两种方法会以当前字体在坐标点 (x, y) 处居中显示指定文本。第二种方法允许您旋转文本。最后两种方法会将文本在坐标点 (x, y) 处左对齐或右对齐。The default font is a Sans Serif font with point size 16. You can use the following method to change the font:
默认字体为无衬线字体,字号为 16。您可以使用以下方法更改字体:To specify the font, you use the
Font
data type, which is defined in Java'sjava.awt
package. This allows you to choose the face, size, and style of the font. For example, the following code fragment sets the font to Arial Bold, 60 point. Theimport
statement allows you to refer toFont
directly, without needing the fully qualified namejava.awt.Font
.
要指定字体,您可以使用Font
数据类型,该数据类型在 Java 的java.awt
包中定义。这使您能够选择字体的类型、大小和样式。例如,以下代码片段将字体设置为 Arial Bold,60 磅。import
语句允许您直接引用Font
,而不需要完整限定名java.awt.Font
。import java.awt.Font; ... Font font = new Font("Arial", Font.BOLD, 60); StdDraw.setFont(font); StdDraw.text(0.5, 0.5, "Hello, World");
Images. You can use the following methods to add images to your drawings:
图像。您可以使用以下方法将图像添加到您的绘图中:-
picture(double x, double y, String filename)
-
picture(double x, double y, String filename, double degrees)
-
picture(double x, double y, String filename, double scaledWidth, double scaledHeight)
-
picture(double x, double y, String filename, double scaledWidth, double scaledHeight, double degrees)
These methods draw the specified image, centered at (x, y). The image must be in a supported file format (typically JPEG, PNG, GIF, TIFF, and BMP). The image will display at its native size, independent of the coordinate system.
这些方法在点(x,y)处绘制指定的图像。图像必须是支持的文件格式(通常为 JPEG,PNG,GIF,TIFF 和 BMP)。图像将以其原始大小显示,与坐标系无关。
Optionally, you can rotate the image a specified number of degrees counterclockwise or rescale it to fit snugly inside a bounding box.
可选地,您可以将图像逆时针旋转指定的度数或重新缩放以紧密适应边界框。Saving to a file. You can save your image to a file using the File → Save menu option. You can also save a file programmatically using the following method:
保存到文件。您可以使用“文件”→“保存”菜单选项将图像保存到文件中。您还可以使用以下方法以编程方式保存文件:You can save the drawing to a file in a supported file format (typically JPEG, PNG, GIF, TIFF, and BMP).
您可以将绘图保存为支持的文件格式(通常为 JPEG、PNG、GIF、TIFF 和 BMP 格式)的文件。File formats. The
StdDraw
class supports reading and writing images to any of the file formats supported byjavax.imageio
(typically JPEG, PNG, GIF, TIFF, and BMP). The file extensions corresponding to JPEG, PNG, GIF, TIFF, and BMP, are.jpg
,.png
,.gif
,.tif
, and.bmp
, respectively.
文件格式。StdDraw
类支持读取和写入到任何javax.imageio
支持的文件格式(通常是 JPEG、PNG、GIF、TIFF 和 BMP)。对应于 JPEG、PNG、GIF、TIFF 和 BMP 的文件扩展名分别为.jpg
、.png
、.gif
、.tif
和.bmp
。We recommend using PNG for drawing that consist solely of geometric shapes and JPEG for drawings that contains pictures. The JPEG file format does not support transparent backgrounds.
我们建议使用 PNG 来绘制仅包含几何形状的图形,而使用 JPEG 来绘制包含图片的图形。JPEG 文件格式不支持透明背景。Clearing the canvas. To clear the entire drawing canvas, you can use the following methods:
清除画布。要清除整个绘图画布,可以使用以下方法:The first method clears the canvas to the default background color (white); the second method allows you to specify the background color. For example,
StdDraw.clear(StdDraw.LIGHT_GRAY)
clears the canvas to a shade of gray. To make the background transparent, callStdDraw.clear(StdDraw.TRANSPARENT)
.
第一种方法将画布清除到默认背景颜色(白色);第二种方法允许您指定背景颜色。例如,StdDraw.clear(StdDraw.LIGHT_GRAY)
将画布清除为灰色。要使背景透明,请调用StdDraw.clear(StdDraw.TRANSPARENT)
。Computer animations and double buffering. Double buffering is one of the most powerful features of standard drawing, enabling computer animations. The following methods control the way in which objects are drawn:
计算机动画和双缓冲。双缓冲是标准绘图中最强大的功能之一,它使计算机动画成为可能。以下方法控制对象绘制的方式:By default, double buffering is disabled, which means that as soon as you call a drawing method—such as
point()
orline()
—the results appear on the screen.
默认情况下,双缓冲是禁用的,这意味着一旦您调用绘图方法,比如point()
或line()
,结果就会立即显示在屏幕上。When double buffering is enabled by calling
enableDoubleBuffering()
, all drawing takes place on the offscreen canvas. The offscreen canvas is not displayed. Only when you callshow()
does your drawing get copied from the offscreen canvas to the onscreen canvas, where it is displayed in the standard drawing window.
当通过调用enableDoubleBuffering()
启用双缓冲时,所有绘图都在离屏画布上进行。离屏画布不会显示。只有当您调用show()
时,您的绘图才会从离屏画布复制到屏幕画布,然后在标准绘图窗口中显示。
You can think of double buffering as collecting all of the lines, points, shapes, and text that you tell it to draw, and then drawing them all simultaneously, upon request.
您可以将双缓冲视为收集您要求其绘制的所有线条、点、形状和文本,然后在请求时同时绘制它们。The most important use of double buffering is to produce computer animations, creating the illusion of motion by rapidly displaying static drawings. To produce an animation, repeat the following four steps:
双缓冲最重要的用途是制作计算机动画,通过快速显示静态图像来创造运动的错觉。要制作动画,请重复以下四个步骤:- Clear the offscreen canvas.
清除屏幕外画布。 - Draw objects on the offscreen canvas.
在离屏画布上绘制对象。 - Copy the offscreen canvas to the onscreen canvas.
将离屏画布复制到屏幕画布上。 - Wait for a short while.
等一小会儿。
The
clear()
,show()
, andpause(int t)
methods support the first, third, and fourth of these steps, respectively.
clear()
、show()
和pause(int t)
方法分别支持这些步骤中的第一、第三和第四步。For example, this code fragment animates two balls moving in a circle.
例如,此代码片段实现了两个球在圆周运动的动画。StdDraw.setScale(-2.0, +2.0); StdDraw.enableDoubleBuffering(); for (double t = 0.0; true; t += 0.02) { double x = Math.sin(t); double y = Math.cos(t); StdDraw.clear(); StdDraw.filledCircle(x, y, 0.1); StdDraw.filledCircle(-x, -y, 0.1); StdDraw.show(); StdDraw.pause(20); }
Without double buffering, the balls would flicker as they move.
没有双缓冲,球在移动时会闪烁。Keyboard and mouse inputs. Standard drawing has very basic support for keyboard and mouse input. It is much less powerful than most user interface libraries provide, but also much simpler. You can use the following methods to intercept mouse events:
键盘和鼠标输入。标准绘图对键盘和鼠标输入的支持非常基础。它的功能远不如大多数用户界面库,但也简单得多。您可以使用以下方法来拦截鼠标事件:The first method tells you whether a mouse button is currently being pressed. The last two methods tells you the x- and y-coordinates of the mouse's current position, using the same coordinate system as the canvas (the unit square, by default). You should use these methods in an animation loop that waits a short while before trying to poll the mouse for its current state.
第一种方法告诉您当前是否按下了鼠标按钮。最后两种方法提供鼠标当前位置的 x 和 y 坐标,使用与画布相同的坐标系统(默认是单位正方形)。您应该在一个动画循环中使用这些方法,该循环在尝试获取鼠标当前状态之前等待一段时间。
You can use the following methods to intercept keyboard events:
您可以使用以下方法来拦截键盘事件:If the user types lots of keys, they will be saved in a list until you process them. The first method tells you whether the user has typed a key (that your program has not yet processed).
如果用户按下了很多键,它们将被保存到一个列表中,直到你处理它们。第一种方法告诉你用户是否输入了一个键(而你的程序尚未处理)。
The second method returns the next key that the user typed (that your program has not yet processed) and removes it from the list of saved keystrokes. The third method tells you whether a key is currently being pressed.
第二种方法返回用户输入的下一个键(尚未被程序处理),并将其从保存的按键列表中移除。第三种方法告诉你某个键是否当前被按下。Accessing control parameters. You can use the following methods to access the current pen color, pen radius, and font:
访问控制参数。您可以使用以下方法访问当前的笔颜色、笔半径和字体:These methods are useful when you want to temporarily change a control parameter and, later, reset it back to its original value.
这些方法在您想要暂时更改控制参数并且之后将其重置回原始值时非常有用。Corner cases. Here are some corner cases.
边界情况。这里是一些边界情况。- Drawing an object outside (or partly outside) the canvas is permitted.
However, only the part of the object that appears inside the canvas
will be visible.
在画布外(或部分在外)绘制物体是允许的。然而,只有在画布内可见的部分才会被显示。 - Due to floating-point issues, an object drawn with an x- or
y-coordinate that is way outside the canvas (such as the line segment
from (0.5, –10^308) to (0.5, 10^308) may not be visible even in the
part of the canvas where it should be.
由于浮点数问题,一个在画布之外的 x 或 y 坐标绘制的对象(例如,从 (0.5, –10^308) 到 (0.5, 10^308) 的线段)即使在应该显示的画布部分也可能不可见。 - Any method that is passed a
null
argument will throw anIllegalArgumentException
.
任何传递null
参数的方法都会抛出一个IllegalArgumentException
。 - Any method that is passed a
Double.NaN
,Double.POSITIVE_INFINITY
, orDouble.NEGATIVE_INFINITY
argument will throw anIllegalArgumentException
.
任何传递Double.NaN
、Double.POSITIVE_INFINITY
或Double.NEGATIVE_INFINITY
参数的方法都会抛出IllegalArgumentException
。
Performance tricks. Standard drawing is capable of drawing large amounts of data. Here are a few tricks and tips:
性能技巧。标准绘图可以绘制大量数据。以下是一些技巧和建议:- Use double buffering for static drawing with a large
number of objects.
That is, call
enableDoubleBuffering()
before the sequence of drawing commands and callshow()
afterwards. Incrementally displaying a complex drawing while it is being created can be intolerably inefficient on many computer systems.
使用双缓冲技术绘制大量对象的静态图形。即,在绘制命令序列之前调用enableDoubleBuffering()
,并在之后调用show()
。在创建复杂图形时逐步显示图形可能会在许多计算机系统上效率极低。 - When drawing computer animations, call
show()
only once per frame, not after drawing each individual object.
在绘制计算机动画时,每帧仅调用一次show()
,而不是在绘制每个单独对象后调用。 - If you call
picture()
multiple times with the same filename, Java will cache the image, so you do not incur the cost of reading from a file each time.
如果您多次使用相同的文件名调用picture()
,Java 会缓存图像,因此您不会每次都产生从文件中读取的开销。
Known bugs and issues.
已知的错误和问题。- The
picture()
methods may not draw the portion of the image that is inside the canvas if the center point (x, y) is outside the canvas. This bug appears only on some systems.
使用picture()
方法可能无法绘制图像在画布内部的部分,如果中心点(x,y)在画布外部。这个错误只在某些系统上出现。
Reference. For additional documentation, see Section 1.5 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
参考文献。有关更多文档,请参见罗伯特·塞奇威克和凯文·韦恩所著《计算机科学:跨学科方法》第 1.5 节。- Author: 作者:
- Robert Sedgewick, Kevin Wayne
Robert Sedgewick,Kevin Wayne
- All Implemented Interfaces:
-
-
Field Summary 字段摘要
Fields 领域 Modifier and Type 修饰符和类型 Field 领域 Description 描述 static Color
AQUA
The color aqua (0, 255, 255).
蔚蓝色(0, 255, 255)。static Color
BLACK
The color black (0, 0, 0).
颜色黑色 (0, 0, 0)。static Color
BLUE
The color blue (0, 0, 255).
蓝色(0,0,255)。static Color
BOOK_BLUE
The shade of blue used in Introduction to Programming in Java.
《Java 程序设计导论》中使用的蓝色阴影。static Color
BOOK_LIGHT_BLUE
The shade of light blue used in Introduction to Programming in Java.
引入 Java 编程中的浅蓝色调。static Color
BOOK_RED
The shade of red used in Algorithms, 4th edition.
《算法(第 4 版)》中使用的红色阴影。static Color
CYAN
The color cyan (0, 255, 255).
青色(0, 255, 255)。static Color
DARK_GRAY
The color dark gray (64, 64, 64).
深灰色(64, 64, 64)。static Color
FUSCIA
The color fuscia (255, 0, 255).
颜色品红(255, 0, 255)。static Color
GRAY
The color gray (128, 128, 128).
灰色(128,128,128)。static Color
GREEN
The color green (0, 128, 0).
绿色 (0, 128, 0)。static Color
LIGHT_GRAY
The color light gray (192, 192, 192).
颜色浅灰色 (192, 192, 192)。static Color
LIME
The color lime (0, 255, 0).
颜色酸橙(0, 255, 0)。static Color
MAGENTA
The color magenta (255, 0, 255).
品红色(255, 0, 255)。static Color
MAROON
The color maroon (128, 0, 0).
褐红色 (128, 0, 0)。static Color
NAVY
The color navy (0, 0, 128).
深海蓝色(0, 0, 128)。static Color
OLIVE
The color olive (128, 128, 0).
橄榄色(128, 128, 0)。static Color
ORANGE
The color orange (255, 200, 0).
橙色 (255, 200, 0)。static Color
PINK
The color pink (255, 175, 175).
粉色 (255, 175, 175)。static Color
PRINCETON_ORANGE
The shade of orange used in Princeton University's identity.
普林斯顿大学标识中使用的橙色调。static Color
PURPLE
The color purple (128, 0, 128).
紫色 (128, 0, 128)。static Color
RED
The color red (255, 0, 0).
红色 (255, 0, 0)。static Color
SILVER
The color silver (192, 192, 192).
银色(192, 192, 192)。static Color
TEAL
The color teal (0, 128, 128).
颜色青色(0, 128, 128)。static Color
TRANSPARENT
A 100% transparent color, for a transparent background.
一个 100%透明的颜色,用于透明背景。static Color
WHITE
The color white (255, 255, 255).
白色 (255, 255, 255)。static Color
YELLOW
The color yellow (255, 255, 0).
黄色(255, 255, 0)。
-
Method Summary 方法摘要
All Methods 所有方法 Static Methods 静态方法 Instance Methods 实例方法 Concrete Methods 具体方法 Modifier and Type 修改器和类型 Method 方法 Description 描述 void
actionPerformed(ActionEvent event)
This method cannot be called directly.
该方法不能直接调用。static 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, y)为中心,从角度 angle1 到 angle2(以度为单位)的指定半径的圆弧。static void
circle(double x, double y, double radius)
Draws a circle of the specified radius, centered at (x, y).
绘制一个以 (x, y) 为中心、指定半径的圆。static void
clear()
Clears the screen using the default background color (white).
使用默认背景色(白色)清除屏幕。static void
clear(Color color)
Clears the screen using the specified background color.
使用指定的背景颜色清除屏幕。static void
close()
Closes the standard drawing window.
关闭标准绘图窗口。static void
disableDoubleBuffering()
Disables double buffering.
禁用双缓冲。static 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, y) 为中心。static void
enableDoubleBuffering()
Enables double buffering.
实现双缓冲。static void
filledCircle(double x, double y, double radius)
Draws a filled circle of the specified radius, centered at (x, y).
绘制一个以 (x, y) 为中心、指定半径的填充圆。static 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, y) 为中心绘制一个填充椭圆。static void
filledPolygon(double[] x, double[] y)
Draws a filled polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).
绘制一个填充的多边形,顶点为 (x0, y0), (x1, y1), ..., (xn–1, yn–1)。static void
filledRectangle(double x, double y, double halfWidth, double halfHeight)
Draws a filled rectangle of the specified size, centered at (x, y).
绘制一个指定大小的填充矩形,中心位于 (x, y)。static void
filledSquare(double x, double y, double halfLength)
Draws a filled square of the specified size, centered at (x, y).
在指定大小的位置(x,y)居中绘制一个填充的正方形。static Color
getBackgroundColor()
Returns the current background color.
返回当前背景颜色。static Font
getFont()
Returns the current font.
返回当前字体。static Color
getPenColor()
Returns the current pen color.
返回当前的笔颜色。static double
getPenRadius()
Returns the current pen radius.
返回当前的画笔半径。static boolean
hasNextKeyTyped()
Returns true if the user has typed a key (that has not yet been processed).
如果用户已经键入了一个尚未处理的键,则返回 true。static boolean
isKeyPressed(int keycode)
Returns true if the given key is being pressed.
返回 true,如果给定的键正在被按下。static boolean
isMousePressed()
Returns true if the mouse is being pressed.
如果鼠标正在被按下,则返回 true。void
keyPressed(KeyEvent event)
This method cannot be called directly.
该方法不能直接调用。void
keyReleased(KeyEvent event)
This method cannot be called directly.
该方法不能被直接调用。void
keyTyped(KeyEvent event)
This method cannot be called directly.
此方法不能被直接调用。static void
line(double x0, double y0, double x1, double y1)
Draws a line segment between (x0, y0) and (x1, y1).
在(x0,y0)和(x1,y1)之间绘制一条线段。static void
main(String[] args)
Test client. 测试客户端。void
mouseClicked(MouseEvent event)
This method cannot be called directly.
此方法不能被直接调用。void
mouseDragged(MouseEvent event)
This method cannot be called directly.
此方法不能直接调用。void
mouseEntered(MouseEvent event)
This method cannot be called directly.
这种方法不能直接调用。void
mouseExited(MouseEvent event)
This method cannot be called directly.
这种方法不能直接调用。void
mouseMoved(MouseEvent event)
This method cannot be called directly.
此方法无法被直接调用。void
mousePressed(MouseEvent event)
This method cannot be called directly.
该方法不能直接调用。void
mouseReleased(MouseEvent event)
This method cannot be called directly.
该方法不能直接调用。static double
mouseX()
Returns the x-coordinate of the mouse.
返回鼠标的 x 坐标。static double
mouseY()
Returns the y-coordinate of the mouse.
返回鼠标的 y 坐标。static char
nextKeyTyped()
Returns the next key that was typed by the user (that your program has not already processed).
返回用户键入的下一个键(您的程序尚未处理的键)。static void
pause(int t)
Pauses for t milliseconds.
暂停 t 毫秒。static void
picture(double x, double y, String filename)
Draws the specified image centered at (x, y).
在(x, y)处绘制指定的图像。static void
picture(double x, double y, String filename, double degrees)
Draws the specified image centered at (x, y), rotated given number of degrees.
在指定角度旋转给定数量的图像,以 (x, y) 为中心绘制。static void
picture(double x, double y, String filename, double scaledWidth, double scaledHeight)
Draws the specified image centered at (x, y), rescaled to the specified bounding box.
绘制指定的图像,使其居中显示在 (x, y) 处,并按指定的边界框进行重新缩放。static void
picture(double x, double y, 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.
以指定图像中心为(x,y),旋转给定角度并重新缩放到指定边界框处。static void
point(double x, double y)
Draws a point centered at (x, y).
绘制以(x,y)为中心的点。static void
polygon(double[] x, double[] y)
Draws a polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).
绘制一个顶点为(x0,y0),(x1,y1),...,(xn-1,yn-1)的多边形。static void
rectangle(double x, double y, double halfWidth, double halfHeight)
Draws a rectangle of the specified size, centered at (x, y).
在指定大小下绘制一个以(x,y)为中心的矩形。static void
save(String filename)
Saves the drawing to a file in a supported file format (typically JPEG, PNG, GIF, TIFF, and BMP).
将绘图保存为支持的文件格式(通常是 JPEG、PNG、GIF、TIFF 和 BMP)的文件中。static void
setCanvasSize()
Sets the canvas (drawing area) to be 512-by-512 pixels.
将画布(绘图区域)设置为 512x512 像素。static void
setCanvasSize(int canvasWidth, int canvasHeight)
Sets the canvas (drawing area) to be width-by-height pixels.
将画布(绘图区域)设置为宽度乘以高度像素。static void
setFont()
Sets the font to the default font (sans serif, 16 point).
将字体设置为默认字体(无衬线,16 磅)。static void
setFont(Font font)
Sets the font to the specified value.
设置字体为指定值。static void
setPenColor()
Sets the pen color to the default color (black).
将笔的颜色设置为默认颜色(黑色)。static void
setPenColor(int red, int green, int blue)
Sets the pen color to the specified RGB color.
将笔颜色设置为指定的 RGB 颜色。static void
setPenColor(Color color)
Sets the pen color to the specified color.
将笔的颜色设置为指定的颜色。static void
setPenRadius()
Sets the pen size to the default size (0.002).
将笔的大小设置为默认大小(0.002)。static void
setPenRadius(double radius)
Sets the radius of the pen to the specified size.
将笔的半径设置为指定的大小。static void
setScale()
Sets both the x-scale and y-scale to the default range (between 0.0 and 1.0).
将 x 轴和 y 轴的刻度设置为默认范围(在 0.0 和 1.0 之间)。static void
setScale(double min, double max)
Sets both the x-scale and y-scale to the (same) specified range.
将 x 轴和 y 轴的刻度设置为(相同的)指定范围。static void
setTitle(String title)
Sets the title of the standard drawing window to the specified string.
将标准绘图窗口的标题设置为指定的字符串。static void
setVisible(boolean isVisible)
Makes the drawing window visible or invisible.
使绘图窗口可见或不可见。static void
setXscale()
Sets the x-scale to the default range (between 0.0 and 1.0).
将 x 轴刻度设置为默认范围(介于 0.0 和 1.0 之间)。static void
setXscale(double min, double max)
Sets the x-scale to the specified range.
将 x 轴范围设置为指定范围。static void
setYscale()
Sets the y-scale to the default range (between 0.0 and 1.0).
将 y 轴比例设置为默认范围(0.0 到 1.0 之间)。static void
setYscale(double min, double max)
Sets the y-scale to the specified range.
将 y 轴的刻度设置为指定范围。static void
show()
Copies offscreen buffer to onscreen buffer.
将离屏缓冲区的内容复制到屏幕缓冲区。static void
square(double x, double y, double halfLength)
Draws a square of the specified size, centered at (x, y).
绘制一个指定大小的正方形,中心位于 (x, y)。static void
text(double x, double y, String text)
Writes the given text string in the current font, centered at (x, y).
在当前字体下,以(x, y)为中心写入给定的文本字符串。static void
text(double x, double y, 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, y) 处并旋转。static void
textLeft(double x, double y, String text)
Writes the given text string in the current font, left-aligned at (x, y).
在当前位置(x, y)以当前字体左对齐写入给定文本字符串。static void
textRight(double x, double y, String text)
Writes the given text string in the current font, right-aligned at (x, y).
在当前字体下,以右对齐方式在坐标 (x, y) 处写入给定的文本字符串。
-
-
-
Field Detail 字段详细信息
-
AQUA 水产学
public static final Color AQUA
The color aqua (0, 255, 255).
颜色青色 (0, 255, 255)。
-
BLACK 黑色
public static final Color BLACK
The color black (0, 0, 0).
黑色(0, 0, 0)。
-
BLUE 蓝色
public static final Color BLUE
The color blue (0, 0, 255).
蓝色 (0, 0, 255)。
-
CYAN 青色
public static final Color CYAN
The color cyan (0, 255, 255).
青色(0, 255, 255)。
-
FUSCIA FUSCIA 达到 2598 年!
public static final Color FUSCIA
The color fuscia (255, 0, 255).
品红(255, 0, 255)。
-
DARK_GRAY 深灰
public static final Color DARK_GRAY
The color dark gray (64, 64, 64).
颜色深灰色 (64, 64, 64)。
-
GRAY 灰色
public static final Color GRAY
The color gray (128, 128, 128).
灰色(128, 128, 128)。
-
GREEN 绿色
public static final Color GREEN
The color green (0, 128, 0).
颜色绿色(0, 128, 0)。
-
LIGHT_GRAY 浅灰色
public static final Color LIGHT_GRAY
The color light gray (192, 192, 192).
颜色是浅灰色 (192, 192, 192)。
-
LIME 石灰
public static final Color LIME
The color lime (0, 255, 0).
颜色酸橙色 (0, 255, 0)。
-
MAGENTA 品红
public static final Color MAGENTA
The color magenta (255, 0, 255).
品红色(255, 0, 255)。
-
MAROON 褐红色
public static final Color MAROON
The color maroon (128, 0, 0).
颜色褐红色(128, 0, 0)。
-
NAVY 海军
public static final Color NAVY
The color navy (0, 0, 128).
深蓝色(0,0,128)。
-
OLIVE 橄榄
public static final Color OLIVE
The color olive (128, 128, 0).
橄榄绿 (128, 128, 0)。
-
ORANGE 橙色
public static final Color ORANGE
The color orange (255, 200, 0).
橙色(255,200,0)。
-
PINK 粉色
public static final Color PINK
The color pink (255, 175, 175).
粉色 (255, 175, 175)。
-
PURPLE 紫色
public static final Color PURPLE
The color purple (128, 0, 128).
紫色 (128, 0, 128)。
-
RED 红色
public static final Color RED
The color red (255, 0, 0).
红色(255, 0, 0)。
-
SILVER 银
public static final Color SILVER
The color silver (192, 192, 192).
颜色银色(192, 192, 192)。
-
TEAL
public static final Color TEAL
The color teal (0, 128, 128).
颜色青绿色 (0, 128, 128)。
-
WHITE 白色
public static final Color WHITE
The color white (255, 255, 255).
颜色白色(255,255,255)。
-
YELLOW 黄色
public static final Color YELLOW
The color yellow (255, 255, 0).
颜色黄色(255,255,0)。
-
TRANSPARENT 透明
public static final Color TRANSPARENT
A 100% transparent color, for a transparent background.
一种 100%透明的颜色,适用于透明背景。
-
BOOK_BLUE 书籍_蓝色
public static final Color BOOK_BLUE
The shade of blue used in Introduction to Programming in Java. It is Pantone 300U. The RGB values are approximately (9, 90, 166).
在 Java 编程导论中使用的蓝色阴影。这是 Pantone 300U。RGB 值大约为(9, 90, 166)。
-
BOOK_LIGHT_BLUE 书籍_浅蓝色
public static final Color BOOK_LIGHT_BLUE
The shade of light blue used in Introduction to Programming in Java. The RGB values are approximately (103, 198, 243).
在《Java 编程导论》中使用的浅蓝色的色调。RGB 值大约为(103,198,243)。
-
BOOK_RED 书籍_红色
public static final Color BOOK_RED
The shade of red used in Algorithms, 4th edition. It is Pantone 1805U. The RGB values are approximately (150, 35, 31).
算法导论(第 4 版)中使用的红色阴影。这是 Pantone 1805U。RGB 值大约为(150,35,31)。
-
PRINCETON_ORANGE 普林斯顿_橙
public static final Color PRINCETON_ORANGE
The shade of orange used in Princeton University's identity. It is PMS 158. The RGB values are approximately (245, 128, 37).
普林斯顿大学标识中使用的橙色色调。它是 PMS 158。RGB 值约为(245, 128, 37)。
-
-
Method Detail 方法详细信息
-
setVisible
public static void setVisible(boolean isVisible)
Makes the drawing window visible or invisible.
使绘图窗口可见或不可见。- Parameters: 参数:
isVisible
- iftrue
, makes the drawing window visible, otherwise hides the drawing window.
isVisible
- 如果true
,则使绘图窗口可见,否则隐藏绘图窗口。
-
setCanvasSize 设置画布大小
public static void setCanvasSize()
Sets the canvas (drawing area) to be 512-by-512 pixels. This also clears the current drawing using the default background color (white). Ordinarily, this method is called once, at the very beginning of a program.
设置画布(绘图区)为 512x512 像素。这也使用默认背景色(白色)清除当前绘图。通常,在程序的最开始调用此方法一次。
-
setCanvasSize setCanvasSize 画布设置大小
public static void setCanvasSize(int canvasWidth, int canvasHeight)
Sets the canvas (drawing area) to be width-by-height pixels. This also clears the current drawing using the default background color (white). Ordinarily, this method is called once, at the very beginning of a program.
设置画布(绘图区域)为宽度乘高度的像素。这还使用默认背景颜色(白色)清除当前绘图。通常,此方法在程序开始时调用一次。- Parameters: 参数:
canvasWidth
- the width as a number of pixels
canvasWidth
- 作为像素的宽度canvasHeight
- the height as a number of pixels
canvasHeight
- 以像素为单位的高度- Throws: 扔:
IllegalArgumentException
- unless bothcanvasWidth
andcanvasHeight
are positive
IllegalArgumentException
- 除非canvasWidth
和canvasHeight
都为正数
-
close 关闭
public static void close()
Closes the standard drawing window. This allows the client program to terminate instead of requiring the user to close the standard drawing window manually. Drawing after calling this method will restore the previous window state.
关闭标准绘图窗口。这样客户端程序可以终止,而不需要用户手动关闭标准绘图窗口。调用此方法后继续绘图将恢复先前的窗口状态。
-
setTitle 设置标题
public static void setTitle(String title)
Sets the title of the standard drawing window to the specified string.
设置标准绘图窗口的标题为指定的字符串。- Parameters: 参数:
title
- the titletitle
- 标题- Throws: 扔掷:
IllegalArgumentException
- iftitle
isnull
IllegalArgumentException
- 如果title
是null
-
setXscale setXscale setScaleX
public static void setXscale()
Sets the x-scale to the default range (between 0.0 and 1.0).
将 x 轴的刻度设置为默认范围(介于 0.0 和 1.0 之间)。
-
setYscale setYscale 设置 Y 轴范围
public static void setYscale()
Sets the y-scale to the default range (between 0.0 and 1.0).
将 y 轴比例设置为默认范围(介于 0.0 和 1.0 之间)。
-
setScale setScale setScale
public static void setScale()
Sets both the x-scale and y-scale to the default range (between 0.0 and 1.0).
将 x 轴和 y 轴的比例设置为默认范围(介于 0.0 和 1.0 之间)。
-
setXscale setXscale setScaleX
public static void setXscale(double min, double max)
Sets the x-scale to the specified range.
将 x 轴比例尺设置为指定范围。- Parameters: 参数:
min
- the minimum value of the x-scale
min
- x 尺度的最小值max
- the maximum value of the x-scale
max
- x 轴比例尺的最大值- Throws: 抛出异常:
IllegalArgumentException
- if(max == min)
IllegalArgumentException
- 如果(max == min)
IllegalArgumentException
- if eithermin
ormax
is either NaN or infinite
如果min
或max
为 NaN 或无穷大,IllegalArgumentException
-
setYscale 设置 Y 轴刻度
public static void setYscale(double min, double max)
Sets the y-scale to the specified range.
设置 y 轴比例尺为指定范围。- Parameters: 参数:
min
- the minimum value of the y-scale
min
- y 轴的最小值max
- the maximum value of the y-scale
max
- y 轴的最大值- Throws: 投掷:
IllegalArgumentException
- if(max == min)
IllegalArgumentException
- 如果(max == min)
IllegalArgumentException
- if eithermin
ormax
is either NaN or infinite
IllegalArgumentException
- 如果min
或max
中任一为 NaN 或无穷大
-
setScale setScale setScale
public static void setScale(double min, double max)
Sets both the x-scale and y-scale to the (same) specified range.
将 x 轴和 y 轴的尺度设置为(相同的)指定范围。- Parameters: 参数:
min
- the minimum value of the x- and y-scales
min
- x 轴和 y 轴刻度的最小值max
- the maximum value of the x- and y-scales
max
- x 轴和 y 轴比例尺的最大值- Throws: 投掷:
IllegalArgumentException
- if(max == min)
IllegalArgumentException
- 如果(max == min)
IllegalArgumentException
- if eithermin
ormax
is either NaN or infinite
如果min
或max
是 NaN 或无限,则IllegalArgumentException
-
clear 清晰
public static void clear()
Clears the screen using the default background color (white).
使用默认背景色(白色)清除屏幕。
-
clear 清晰
public static void clear(Color color)
Clears the screen using the specified background color. To make the background transparent, useStdDraw.TRANSPARENT
.
使用指定的背景颜色清除屏幕。要使背景透明,请使用StdDraw.TRANSPARENT
。- Parameters: 参数:
color
- the color to make the background
color
- 用于设置背景颜色的属性- Throws: 投掷:
IllegalArgumentException
- ifcolor
isnull
IllegalArgumentException
- 如果color
是null
-
getPenRadius
public static double getPenRadius()
Returns the current pen radius.
返回当前笔刷半径。- Returns: 收益:
- the current value of the pen radius
笔半径的当前数值
-
setPenRadius 设置笔尖半径
public static void setPenRadius()
Sets the pen size to the default size (0.002). The pen is circular, so that lines have rounded ends, and when you set the pen radius and draw a point, you get a circle of the specified radius. The pen radius is not affected by coordinate scaling.
将笔大小设置为默认值(0.002)。笔是圆形的,因此线条的末端是圆的,当您设置笔的半径并绘制一个点时,您将得到一个指定半径的圆。笔的半径不受坐标缩放的影响。
-
setPenRadius
public static void setPenRadius(double radius)
Sets the radius of the pen to the specified size. The pen is circular, so that lines have rounded ends, and when you set the pen radius and draw a point, you get a circle of the specified radius. The pen radius is not affected by coordinate scaling.
设置笔的半径为指定的大小。笔是圆形的,因此线条的末端是圆润的,当你设置笔的半径并绘制一个点时,你会得到一个指定半径的圆。笔的半径不受坐标缩放的影响。- Parameters: 参数:
radius
- the radius of the pen
radius
- 钢笔的半径- Throws: 投掷:
IllegalArgumentException
- ifradius
is negative, NaN, or infinite
IllegalArgumentException
- 如果radius
为负数、NaN(非数字值)或无穷大
-
getPenColor 获取笔颜色
public static Color getPenColor()
Returns the current pen color.
返回当前的笔颜色。- Returns: 回报:
- the current pen color
当前的笔颜色
-
getBackgroundColor 获取背景颜色
public static Color getBackgroundColor()
Returns the current background color.
返回当前背景颜色。- Returns: 返回:
- the current background color
当前背景颜色
-
setPenColor 设置笔颜色
public static void setPenColor()
Sets the pen color to the default color (black).
设置笔的颜色为默认颜色(黑色)。
-
setPenColor 设置画笔颜色
public static void setPenColor(Color color)
Sets the pen color to the specified color.
将笔的颜色设置为指定的颜色。There are a number predefined pen colors, such as
StdDraw.BLACK
,StdDraw.WHITE
,StdDraw.RED
,StdDraw.GREEN
, andStdDraw.BLUE
.
有一些预定义的笔颜色,例如StdDraw.BLACK
、StdDraw.WHITE
、StdDraw.RED
、StdDraw.GREEN
和StdDraw.BLUE
。- Parameters: 参数:
color
- the color to make the pen
color
- 制作钢笔的颜色- Throws: 抛出异常:
IllegalArgumentException
- ifcolor
isnull
IllegalArgumentException
- 如果color
是null
-
setPenColor 设置画笔颜色
public static void setPenColor(int red, int green, int blue)
Sets the pen color to the specified RGB color.
设置笔的颜色为指定的 RGB 颜色。- Parameters: 参数:
red
- the amount of red (between 0 and 255)
red
- 红色的数量(在 0 和 255 之间)green
- the amount of green (between 0 and 255)
green
- 绿色的量(介于 0 和 255 之间)blue
- the amount of blue (between 0 and 255)
blue
- 蓝色的数量(介于 0 和 255 之间)- Throws: 投掷:
IllegalArgumentException
- ifred
,green
, orblue
is outside its prescribed range
如果red
、green
或blue
超出了规定范围IllegalArgumentException
-
getFont 获取字体
public static Font getFont()
Returns the current font.
返回当前字体。- Returns: 返回:
- the current font 当前字体
-
setFont setFont 设置字体
public static void setFont()
Sets the font to the default font (sans serif, 16 point).
将字体设置为默认字体(无衬线字体,16 磅)。
-
setFont 设置字体
public static void setFont(Font font)
Sets the font to the specified value.
将字体设置为指定值。- Parameters: 参数:
font
- the fontfont
- 字体- Throws: 投掷:
IllegalArgumentException
- iffont
isnull
IllegalArgumentException
- 如果font
是null
-
line 线
public static void line(double x0, double y0, double x1, double y1)
Draws a line segment between (x0, y0) and (x1, y1).
在(x0,y0)和(x1,y1)之间绘制一条线段。- Parameters: 参数:
x0
- the x-coordinate of one endpoint
x0
- 一个端点的 x 坐标y0
- the y-coordinate of one endpoint
y0
- 一个端点的 y 坐标x1
- the x-coordinate of the other endpoint
x1
- 另一个端点的 x 坐标y1
- the y-coordinate of the other endpoint
y1
- 另一端点的 y 坐标- Throws: 抛出异常:
IllegalArgumentException
- if any coordinate is either NaN or infinite
IllegalArgumentException
- 如果任何坐标是 NaN 或无穷大
-
point 点
public static void point(double x, double y)
Draws a point centered at (x, y). The point is a filled circle whose radius is equal to the pen radius. To draw a single-pixel point, first set the pen radius to 0.
绘制以(x,y)为中心的点。该点是一个填充圆,其半径等于画笔半径。要绘制单像素点,请先将画笔半径设置为 0。- Parameters: 参数:
x
- the x-coordinate of the point
x
- 点的 x 坐标y
- the y-coordinate of the point
y
- 该点的 y 坐标- Throws: 投掷:
IllegalArgumentException
- if eitherx
ory
is either NaN or infinite
IllegalArgumentException
- 如果x
或y
为 NaN 或无穷大
-
circle 圆形
public static void circle(double x, double y, double radius)
Draws a circle of the specified radius, centered at (x, y).
绘制一个以 (x, y) 为中心、指定半径的圆。- Parameters: 参数:
x
- the x-coordinate of the center of the circle
x
- 圆心的 x 坐标y
- the y-coordinate of the center of the circle
y
- 圆的中心的 y 坐标radius
- the radius of the circle
radius
- 圆的半径- Throws: 投掷:
IllegalArgumentException
- ifradius
is negative
IllegalArgumentException
- 如果radius
为负IllegalArgumentException
- if any argument is either NaN or infinite
IllegalArgumentException
- 如果任何参数是 NaN 或无限的
-
filledCircle 填充圆形
public static void filledCircle(double x, double y, double radius)
Draws a filled circle of the specified radius, centered at (x, y).
绘制一个指定半径的填充圆,中心位于 (x, y) 处。- Parameters: 参数:
x
- the x-coordinate of the center of the circle
x
- 圆心的 x 坐标y
- the y-coordinate of the center of the circle
y
- 圆心的 y 坐标radius
- the radius of the circle
radius
- 圆的半径- Throws: 抛出异常:
IllegalArgumentException
- ifradius
is negative
IllegalArgumentException
- 如果radius
是负数IllegalArgumentException
- if any argument is either NaN or infinite
IllegalArgumentException
- 如果任何参数是 NaN 或无穷大
-
ellipse 椭圆
public static 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, y) 为中心,指定的半主轴和半次轴的椭圆。- Parameters: 参数:
x
- the x-coordinate of the center of the ellipse
x
- 椭圆中心的 x 坐标y
- the y-coordinate of the center of the ellipse
y
- 椭圆中心的纵坐标semiMajorAxis
- is the semimajor axis of the ellipse
semiMajorAxis
- 是椭圆的半长轴semiMinorAxis
- is the semiminor axis of the ellipse
semiMinorAxis
- 是椭圆的半短轴- Throws: 抛出异常:
IllegalArgumentException
- if eithersemiMajorAxis
orsemiMinorAxis
is negative
IllegalArgumentException
- 如果semiMajorAxis
或semiMinorAxis
为负IllegalArgumentException
- if any argument is either NaN or infinite
IllegalArgumentException
- 如果任何参数是 NaN 或无穷大
-
filledEllipse 填充椭圆
public static 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,y)为中心绘制一个填充椭圆。- Parameters: 参数:
x
- the x-coordinate of the center of the ellipse
x
- 椭圆的中心的 x 坐标y
- the y-coordinate of the center of the ellipse
y
- 椭圆中心的 y 坐标semiMajorAxis
- is the semimajor axis of the ellipse
semiMajorAxis
- 是椭圆的半主轴semiMinorAxis
- is the semiminor axis of the ellipse
semiMinorAxis
- 是椭圆的半短轴- Throws: 抛出异常:
IllegalArgumentException
- if eithersemiMajorAxis
orsemiMinorAxis
is negative
IllegalArgumentException
- 如果semiMajorAxis
或semiMinorAxis
其中一个为负数IllegalArgumentException
- if any argument is either NaN or infinite
IllegalArgumentException
- 如果任何参数是 NaN 或无穷大
-
arc 弧形
public static 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, y) 为中心、半径为指定值的圆弧,从角度 angle1 绕至角度 angle2(以度为单位)。- Parameters: 参数:
x
- the x-coordinate of the center of the circle
x
- 圆心的 x 坐标y
- the y-coordinate of the center of the circle
y
- 圆心的纵坐标radius
- the radius of the circle
radius
- 圆的半径angle1
- the starting angle. 0 would mean an arc beginning at 3 o'clock.
angle1
- 起始角度。0 表示弧从 3 点钟位置开始。angle2
- the angle at the end of the arc. For example, if you want a 90 degree arc, then angle2 should be angle1 + 90.
angle2
- 弧线末端的角度。例如,如果您想要一个 90 度的弧线,那么 angle2 应该是 angle1 + 90。- Throws: 甩:
IllegalArgumentException
- ifradius
is negative
IllegalArgumentException
- 如果radius
是负数IllegalArgumentException
- if any argument is either NaN or infinite
IllegalArgumentException
- 如果任何参数是 NaN 或无穷大
-
square 平方
public static void square(double x, double y, double halfLength)
Draws a square of the specified size, centered at (x, y).
绘制一个指定大小的正方形,中心位于 (x, y) 处。- Parameters: 参数:
x
- the x-coordinate of the center of the square
x
- 正方形中心的 x 坐标y
- the y-coordinate of the center of the square
y
- 正方形中心的 y 坐标halfLength
- one half the length of any side of the square
halfLength
- 正方形任一边长的一半- Throws: 投掷:
IllegalArgumentException
- ifhalfLength
is negative
IllegalArgumentException
- 如果halfLength
是负数IllegalArgumentException
- if any argument is either NaN or infinite
IllegalArgumentException
- 如果任何参数为 NaN 或无限
-
filledSquare 填充的正方形
public static void filledSquare(double x, double y, double halfLength)
Draws a filled square of the specified size, centered at (x, y).
绘制一个指定大小的填充正方形,中心位于 (x, y)。- Parameters: 参数:
x
- the x-coordinate of the center of the square
x
- 正方形中心的 x 坐标y
- the y-coordinate of the center of the square
y
- 正方形中心的 y 坐标halfLength
- one half the length of any side of the square
halfLength
- 正方形任一边长的一半- Throws: 投掷:
IllegalArgumentException
- ifhalfLength
is negative
IllegalArgumentException
- 如果halfLength
为负IllegalArgumentException
- if any argument is either NaN or infinite
如果任何参数是 NaN 或无限
-
rectangle 矩形
public static void rectangle(double x, double y, double halfWidth, double halfHeight)
Draws a rectangle of the specified size, centered at (x, y).
绘制一个指定大小的矩形,中心位于 (x, y)。- Parameters: 参数:
x
- the x-coordinate of the center of the rectangle
x
- 矩形中心的 x 坐标y
- the y-coordinate of the center of the rectangle
y
- 矩形中心的 y 坐标halfWidth
- one half the width of the rectangle
halfWidth
- 长方形的一半宽度halfHeight
- one half the height of the rectangle
halfHeight
- 矩形高度的一半- Throws: 投掷:
IllegalArgumentException
- if eitherhalfWidth
orhalfHeight
is negative
IllegalArgumentException
- 如果halfWidth
或halfHeight
为负数IllegalArgumentException
- if any argument is either NaN or infinite
如果任何参数是 NaN 或无穷大
-
filledRectangle 填充矩形
public static void filledRectangle(double x, double y, double halfWidth, double halfHeight)
Draws a filled rectangle of the specified size, centered at (x, y).
绘制一个指定大小的已填充矩形,以 (x, y) 为中心。- Parameters: 参数:
x
- the x-coordinate of the center of the rectangle
x
- 矩形中心的 x 坐标y
- the y-coordinate of the center of the rectangle
y
- 矩形中心的 y 坐标halfWidth
- one half the width of the rectangle
halfWidth
- 矩形宽度的一半halfHeight
- one half the height of the rectangle
halfHeight
- 矩形高度的一半- Throws: 投掷:
IllegalArgumentException
- if eitherhalfWidth
orhalfHeight
is negative
IllegalArgumentException
- 如果halfWidth
或halfHeight
为负IllegalArgumentException
- if any argument is either NaN or infinite
IllegalArgumentException
- 如果任何参数为 NaN 或无穷大
-
polygon 多边形
public static void polygon(double[] x, double[] y)
Draws a polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).
绘制具有顶点(x0,y0),(x1,y1),...,(xn-1,yn-1)的多边形。- Parameters: 参数:
x
- an array of all the x-coordinates of the polygon
x
- 多边形所有 x 坐标的数组y
- an array of all the y-coordinates of the polygon
y
- 多边形所有 y 坐标的数组- Throws: 抛掷:
IllegalArgumentException
- unlessx[]
andy[]
are of the same length
IllegalArgumentException
- 除非x[]
和y[]
的长度相同IllegalArgumentException
- if any coordinate is either NaN or infinite
IllegalArgumentException
- 如果任何坐标是 NaN 或者无穷大IllegalArgumentException
- if eitherx[]
ory[]
isnull
IllegalArgumentException
- 如果x[]
或y[]
中的任一项是null
-
filledPolygon 填充多边形
public static void filledPolygon(double[] x, double[] y)
Draws a filled polygon with the vertices (x0, y0), (x1, y1), ..., (xn–1, yn–1).
绘制一个填充的多边形,顶点为 (x0, y0), (x1, y1), ..., (xn–1, yn–1)。- Parameters: 参数:
x
- an array of all the x-coordinates of the polygon
x
- 多边形所有 x 坐标的数组y
- an array of all the y-coordinates of the polygon
y
- 多边形所有 y 坐标的数组- Throws: 投掷:
IllegalArgumentException
- unlessx[]
andy[]
are of the same length
IllegalArgumentException
- 除非x[]
和y[]
的长度相同IllegalArgumentException
- if any coordinate is either NaN or infinite
IllegalArgumentException
- 如果任何坐标是 NaN 或无穷大IllegalArgumentException
- if eitherx[]
ory[]
isnull
IllegalArgumentException
- 如果x[]
或y[]
为null
-
picture 图片
public static void picture(double x, double y, String filename)
Draws the specified image centered at (x, y). The supported image formats are typically JPEG, PNG, GIF, TIFF, and BMP. 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).
在指定位置(x,y)居中绘制图像。支持的图像格式通常为 JPEG、PNG、GIF、TIFF 和 BMP。为了优化,图片会被缓存,因此多次重绘相同图像时不会有性能惩罚(例如在动画中)。
However, if you change the picture file after drawing it, subsequent calls will draw the original picture.
然而,如果在绘制后更改了图片文件,后续调用将绘制原始图片。- Parameters: 参数:
x
- the center x-coordinate of the image
x
- 图像的中心 x 坐标y
- the center y-coordinate of the image
y
- 图像的中心 y 坐标filename
- the name of the image/picture, e.g., "ball.gif"
filename
- 图像/图片的名称,例如,“ball.gif”- Throws: 投掷:
IllegalArgumentException
- if the image filename is invalid
IllegalArgumentException
- 如果图像文件名无效IllegalArgumentException
- if eitherx
ory
is either NaN or infinite
如果x
或y
是 NaN 或无穷大,IllegalArgumentException
-
picture 图片
public static void picture(double x, double y, String filename, double degrees)
Draws the specified image centered at (x, y), rotated given number of degrees. The supported image formats are typically JPEG, PNG, GIF, TIFF, and BMP.
以给定的度数旋转指定的图像以(x, y)为中心。通常支持的图像格式包括 JPEG、PNG、GIF、TIFF 和 BMP。- Parameters: 参数:
x
- the center x-coordinate of the image
x
- 图像的中心 x 坐标y
- the center y-coordinate of the image
y
- 图像的中心 y 坐标filename
- the name of the image/picture, e.g., "ball.gif"
filename
- 图像/图片的名称,例如:“ball.gif”degrees
- is the number of degrees to rotate counterclockwise
degrees
- 是逆时针旋转的角度数- Throws: 抛出异常:
IllegalArgumentException
- if the image filename is invalid
IllegalArgumentException
- 如果图像文件名无效IllegalArgumentException
- ifx
,y
,degrees
is NaN or infinite
IllegalArgumentException
- 如果x
,y
,degrees
是 NaN 或无穷大IllegalArgumentException
- iffilename
isnull
IllegalArgumentException
- 如果filename
是null
-
picture 图片
public static void picture(double x, double y, 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 typically JPEG, PNG, GIF, TIFF, and BMP.
在指定的边界框内,绘制居中于 (x, y) 的指定图像,并进行缩放。支持的图像格式通常包括 JPEG、PNG、GIF、TIFF 和 BMP。- Parameters: 参数:
x
- the center x-coordinate of the image
x
- 图像的中心 x 坐标y
- the center y-coordinate of the image
y
- 图像的中心 y 坐标filename
- the name of the image/picture, e.g., "ball.gif"
filename
- 图像/图片的名称,例如 "ball.gif"scaledWidth
- the width of the scaled image (in screen coordinates)
scaledWidth
- 缩放图像的宽度(以屏幕坐标表示)scaledHeight
- the height of the scaled image (in screen coordinates)
scaledHeight
- 缩放后图像的高度(以屏幕坐标为单位)- Throws: 投掷:
IllegalArgumentException
- if eitherscaledWidth
orscaledHeight
is negative
IllegalArgumentException
- 如果scaledWidth
或scaledHeight
为负数IllegalArgumentException
- if the image filename is invalid
IllegalArgumentException
- 如果图片文件名无效IllegalArgumentException
- ifx
ory
is either NaN or infinite
IllegalArgumentException
- 如果x
或y
是 NaN 或无穷大IllegalArgumentException
- iffilename
isnull
IllegalArgumentException
- 如果filename
是null
-
picture 图片
public static void picture(double x, double y, 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 typically JPEG, PNG, GIF, TIFF, and BMP.
在指定位置(x, y)以指定角度旋转,并重新缩放到指定边界框的中心绘制图像。支持的图像格式通常为 JPEG、PNG、GIF、TIFF 和 BMP。- Parameters: 参数:
x
- the center x-coordinate of the image
x
- 图像的中心 x 坐标y
- the center y-coordinate of the image
y
- 图像的中心 y 坐标filename
- the name of the image/picture, e.g., "ball.gif"
filename
- 图像/图片的名称,例如,“ball.gif”scaledWidth
- the width of the scaled image (in screen coordinates)
scaledWidth
- 缩放图像的宽度(以屏幕坐标表示)scaledHeight
- the height of the scaled image (in screen coordinates)
scaledHeight
- 缩放图像的高度(以屏幕坐标表示)degrees
- is the number of degrees to rotate counterclockwise
degrees
- 是逆时针旋转的度数- Throws: 抛出异常:
IllegalArgumentException
- if eitherscaledWidth
orscaledHeight
is negative
IllegalArgumentException
- 如果scaledWidth
或scaledHeight
为负IllegalArgumentException
- if the image filename is invalid
IllegalArgumentException
- 如果图像文件名无效
-
text 文本
public static void text(double x, double y, String text)
Writes the given text string in the current font, centered at (x, y).
在当前字体中心坐标为(x,y)处书写给定的文本字符串。- Parameters: 参数:
x
- the center x-coordinate of the text
x
- 文本的中心 X 坐标y
- the center y-coordinate of the text
y
- 文本的中心 y 坐标text
- the text to write
text
- 要写的文本- Throws: 投掷:
IllegalArgumentException
- iftext
isnull
IllegalArgumentException
-如果text
是null
IllegalArgumentException
- ifx
ory
is either NaN or infinite
IllegalArgumentException
- 如果x
或y
是 NaN 或无穷大
-
text I'm sorry, but it seems like you forgot to provide the source text for translation. Please provide the text you would like me to translate into Simplified Chinese
public static void text(double x, double y, 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, y)旋转指定角度后,写出给定的文本字符串。- Parameters: 参数:
x
- the center x-coordinate of the text
x
- 文本的中心 x 坐标y
- the center y-coordinate of the text
y
- 文本的中心 y 坐标text
- the text to write
text
- 要写的文本degrees
- is the number of degrees to rotate counterclockwise
degrees
- 是逆时针旋转的度数- Throws: 抛掷:
IllegalArgumentException
- iftext
isnull
IllegalArgumentException
- 如果text
是null
IllegalArgumentException
- ifx
,y
, ordegrees
is either NaN or infinite
IllegalArgumentException
- 如果x
,y
或者degrees
是 NaN(不是数字)或者无穷大
-
textLeft 文本左侧
public static void textLeft(double x, double y, String text)
Writes the given text string in the current font, left-aligned at (x, y).
在当前字体下,以左对齐方式在(x,y)处写入给定的文本字符串。- Parameters: 参数:
x
- the x-coordinate of the text
x
- 文本的 x 坐标y
- the y-coordinate of the text
y
- 文本的 y 坐标text
- the texttext
- 文本- Throws: 投掷:
IllegalArgumentException
- iftext
isnull
IllegalArgumentException
- 如果text
是null
IllegalArgumentException
- ifx
ory
is either NaN or infinite
IllegalArgumentException
- 如果x
或y
是 NaN 或无穷大,则
-
textRight 文本右
public static void textRight(double x, double y, String text)
Writes the given text string in the current font, right-aligned at (x, y).
在当前字体下,将给定的文本字符串以右对齐方式写入到位置(x, y)。- Parameters: 参数:
x
- the x-coordinate of the text
x
- 文本的 x 坐标y
- the y-coordinate of the text
y
- 文本的 y 坐标text
- the text to write
text
- 要写的文本- Throws: 抛出:
IllegalArgumentException
- iftext
isnull
IllegalArgumentException
- 如果text
是null
IllegalArgumentException
- ifx
ory
is either NaN or infinite
IllegalArgumentException
- 如果x
或y
为 NaN 或无穷大
-
pause 暂停
public static void pause(int t)
Pauses for t milliseconds. This method is intended to support computer animations.
暂停 t 毫秒。该方法旨在支持计算机动画。- Parameters: 参数:
t
- number of milliseconds
t
- 毫秒数- Throws: 抛出:
IllegalArgumentException
- ift
is negative
IllegalArgumentException
- 如果t
是负数
-
show 展示
public static void show()
Copies offscreen buffer to onscreen buffer. There is no reason to call this method unless double buffering is enabled.
将屏幕缓冲区的副本复制到屏幕缓冲区。除非启用了双缓冲,否则没有理由调用此方法。
-
enableDoubleBuffering 启用双缓冲
public static void enableDoubleBuffering()
Enables double buffering. All subsequent calls to drawing methods such asline()
,circle()
, andsquare()
will be deferred until the next call to show(). Useful for animations.
启用双缓冲。对于诸如line()
、circle()
和square()
等绘图方法的所有后续调用都将推迟到下一次 show() 的调用。适用于动画。
-
disableDoubleBuffering 禁用双缓冲
public static void disableDoubleBuffering()
Disables double buffering. All subsequent calls to drawing methods such asline()
,circle()
, andsquare()
will be displayed on screen when called. This is the default.
禁用双缓冲。随后对绘图方法的所有调用,如line()
、circle()
和square()
,在调用时将显示在屏幕上。这是默认设置。
-
save 保存
public static void save(String filename)
Saves the drawing to a file in a supported file format (typically JPEG, PNG, GIF, TIFF, and BMP). The filetype extension must be.jpg
,.png
,.gif
,.bmp
, or.tif
.
将绘图保存为支持的文件格式的文件(通常为 JPEG、PNG、GIF、TIFF 和 BMP)。文件类型扩展名必须是.jpg
、.png
、.gif
、.bmp
或.tif
。- Parameters: 参数:
filename
- the name of the file
filename
- 文件的名称- Throws: 投掷:
IllegalArgumentException
- iffilename
isnull
IllegalArgumentException
- 如果filename
是null
IllegalArgumentException
- iffilename
is the empty string
IllegalArgumentException
- 如果filename
是空字符串IllegalArgumentException
- iffilename
has invalid filetype extension
IllegalArgumentException
- 如果filename
具有无效的文件类型扩展名IllegalArgumentException
- if cannot write the filefilename
IllegalArgumentException
- 如果无法写入文件filename
-
actionPerformed 执行操作
public void actionPerformed(ActionEvent event)
This method cannot be called directly.
这种方法不能被直接调用。- Specified by: 指定为:
actionPerformed
in interfaceActionListener
在接口ActionListener
中的actionPerformed
-
isMousePressed
public static boolean isMousePressed()
Returns true if the mouse is being pressed.
如果鼠标正在被按下,则返回 true。- Returns: 返回:
true
if the mouse is being pressed;false
otherwise
如果鼠标被按下,则为true
;否则为false
-
mouseX 鼠标 X 位置
public static double mouseX()
Returns the x-coordinate of the mouse.
返回鼠标的 x 坐标。- Returns: 返回:
- the x-coordinate of the mouse
鼠标的 x 坐标
-
mouseY 鼠标 Y
public static double mouseY()
Returns the y-coordinate of the mouse.
返回鼠标的 y 坐标。- Returns: 返回:
- y-coordinate of the mouse
鼠标的 y 坐标
-
mouseClicked 鼠标点击
public void mouseClicked(MouseEvent event)
This method cannot be called directly.
该方法不能直接调用。- Specified by: 指定由:
mouseClicked
in interfaceMouseListener
在接口MouseListener
中的mouseClicked
-
mouseEntered
public void mouseEntered(MouseEvent event)
This method cannot be called directly.
该方法无法直接调用。- Specified by: Specified by: 由...确定:
mouseEntered
in interfaceMouseListener
在接口MouseListener
中的mouseEntered
-
mouseExited 鼠标退出
public void mouseExited(MouseEvent event)
This method cannot be called directly.
此方法无法直接调用。- Specified by: 指定为:
mouseExited
in interfaceMouseListener
接口中的mouseExited
MouseListener
-
mousePressed 鼠标按下
public void mousePressed(MouseEvent event)
This method cannot be called directly.
该方法不能直接调用。- Specified by: 由以下规定:
mousePressed
in interfaceMouseListener
接口MouseListener
中的mousePressed
-
mouseReleased 鼠标释放
public void mouseReleased(MouseEvent event)
This method cannot be called directly.
这种方法不能被直接调用。- Specified by: 指定者:
mouseReleased
in interfaceMouseListener
接口中的mouseReleased
MouseListener
-
mouseDragged
public void mouseDragged(MouseEvent event)
This method cannot be called directly.
该方法不能直接调用。- Specified by: 指定为:
mouseDragged
in interfaceMouseMotionListener
接口中的mouseDragged
MouseMotionListener
-
mouseMoved 鼠标移动
public void mouseMoved(MouseEvent event)
This method cannot be called directly.
此方法无法被直接调用。- Specified by: 指定为:
mouseMoved
in interfaceMouseMotionListener
在接口MouseMotionListener
中的mouseMoved
-
hasNextKeyTyped
public static boolean hasNextKeyTyped()
Returns true if the user has typed a key (that has not yet been processed).
如果用户已输入尚未处理的按键,则返回 true。- Returns: 返回值:
true
if the user has typed a key (that has not yet been processed bynextKeyTyped()
;false
otherwise
如果用户输入了一个尚未被nextKeyTyped()
处理的键,则为true
;否则为false
-
nextKeyTyped
public static char nextKeyTyped()
Returns the next key that was typed by the user (that your program has not already processed). This method should be preceded by a call tohasNextKeyTyped()
to ensure that there is a next key to process. This method returns a Unicode character corresponding to the key typed (such as'a'
or'A'
). It cannot identify action keys (such as F1 and arrow keys) or modifier keys (such as control).
返回用户输入的下一个键(您的程序尚未处理的)。此方法应在调用hasNextKeyTyped()
之前,以确保有下一个键可供处理。此方法返回一个与输入的键相对应的 Unicode 字符(例如'a'
或'A'
)。它无法识别动作键(例如 F1 和箭头键)或修饰键(例如控制键)。- Returns: 返回值:
- the next key typed by the user (that your program has not already processed).
下一个用户输入的键(您的程序尚未处理的)。 - Throws: 抛出:
NoSuchElementException
- if there is no remaining key
NoSuchElementException
- 如果没有剩余的钥匙
-
isKeyPressed isKeyPressed 按下按键
public static boolean isKeyPressed(int keycode)
Returns true if the given key is being pressed.
如果按键被按下,则返回 true。This method takes the keycode (corresponding to a physical key) as an argument. 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.
该方法以按键代码(对应于实际按键)作为参数。它可以处理动作键(如 F1 和箭头键)和修饰键(如 Shift 和 Control)。要查看按键码的描述,请参阅KeyEvent
。- Parameters: 参数:
keycode
- the key to check if it is being pressed
keycode
- 用于检查是否被按下的关键- Returns: 收益:
true
ifkeycode
is currently being pressed;false
otherwise
如果当前正在按下keycode
,则为true
;否则为false
-
keyTyped 键入的键
public void keyTyped(KeyEvent event)
This method cannot be called directly.
该方法不能被直接调用。- Specified by: 指定为:
keyTyped
in interfaceKeyListener
在接口KeyListener
中的keyTyped
-
keyPressed 按键被按下
public void keyPressed(KeyEvent event)
This method cannot be called directly.
此方法不能被直接调用。- Specified by: 指定者:
keyPressed
in interfaceKeyListener
在接口KeyListener
中的keyPressed
-
keyReleased
public void keyReleased(KeyEvent event)
This method cannot be called directly.
这种方法不能直接调用。- Specified by: 指定为:
keyReleased
in interfaceKeyListener
在接口KeyListener
中的keyReleased
-
main 主界面
public static void main(String[] args)
Test client. 测试客户。- Parameters: 参数:
args
- the command-line arguments
args
- 命令行参数
-
-