📄 main.java
字号:
import java.awt.*;
class Main extends Frame implements Runnable {
int dotSize = 15;
Main() {
super("setColor Example");
setSize(150, 150);
show();
(new Thread(this)).start();
}
// Returns an integer in the range [0..r-1].
int random(int r) {
return (int)(Math.floor(Math.random()*r));
}
public void update(Graphics g) {
Insets insets = this.getInsets();
int w = getSize().width-insets.left-insets.right;
int h = getSize().height-insets.top-insets.bottom;
for (int i=0; i<10; i++) {
int x = random(w), y = random(h);
g.setColor(new Color(random(256), random(256), random(256)));
g.fillOval(x-x%dotSize, y-y%dotSize, dotSize, dotSize);
}
}
public void run() {
while (true) {
try {Thread.sleep(100);} catch (Exception e) {}
repaint();
}
}
static public void main(String[] args) {
new Main();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -