📄 randomline.java
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -