randomline.java
来自「Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套」· Java 代码 · 共 29 行
JAVA
29 行
// Figure 11.4import javax.swing.JComponent;import java.awt.*;public class RandomLine extends JComponent { private int x1, y1, x2, y2; /** post: 0 <= x1 <= 399 and 0 <= y1 <= 399 * and 0 <= x2 <= 399 and 0 <= y2 <= 399 * and getBackground() == Color.black */ public RandomLine() { setBounds(0, 0, 400, 400); x1 = (int)(Math.random()*400); x2 = (int)(Math.random()*400); y1 = (int)(Math.random()*400); y2 = (int)(Math.random()*400); setBackground(Color.black); } /** post: a black line is drawn from (x1,y1) to (x2,y2) * and the line is colored getBackground() */ public void paint(Graphics g) { g.setColor( getBackground() ); g.drawLine(x1, y1, x2, y2); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?