📄 spotsandlines.java
字号:
/*
* SpotsAndLines.java E.L. 2001-08-12
*
* An applet with filled circles and lines between the circles.
* The applet window is 400 pixels in the horizontal direction,
* and 300 pixels in the vertical direction.
*/
import java.awt.*;
import javax.swing.*;
public class SpotsAndLines extends JApplet {
public void init() {
Container content = getContentPane();
Drawing theDrawing = new Drawing();
content.add(theDrawing);
}
}
class Drawing extends JPanel {
private static final int windowWidth = 400; // have to agree
private static final int windowHeight = 300; // with the html file
private static final int diameter = 20;
private static final int center = diameter / 2;
private static final int noOfLines = 10;
public void paintComponent(Graphics window) {
super.paintComponent(window);
int x = (int) ((windowWidth - diameter) * Math.random() + 1);
int y = (int) ((windowHeight - diameter) * Math.random() + 1);
window.fillOval(x, y, diameter, diameter);
int counter = 0;
while (counter < noOfLines) {
int lastX = x;
int lastY = y;
x = (int) ((windowWidth - diameter) * Math.random() + 1);
y = (int) ((windowHeight - diameter) * Math.random() + 1);
window.drawLine(lastX + center, lastY + center, x + center, y + center);
window.fillOval(x, y, diameter, diameter);
counter++;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -