📄 spottest.java
字号:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class SpotTest extends Applet {
/* SpotTest J M Bishop Aug 2000
* ========
*
* Draws spots of different colours
*
* Illustrates simple threads
*/
int mx, my;
int radius = 10;
int boardSize = 200;
int change;
public void init() {
boardSize = getSize().width - 1;
change = boardSize-radius;
// creates and starts three threads
new Spots(Color.red).start();
new Spots(Color.blue).start();
new Spots(Color.green).start();
}
class Spots extends Thread {
Color colour;
// the constructor records the thread's colour
Spots(Color c) {
colour = c;
}
// a very simple run method
public void run () {
while (true) {
draw();
try {
sleep (500); // millisecs
}
catch (InterruptedException e) {
}
}
}
public void draw() {
Graphics g = getGraphics();
g.setColor(colour);
// calculate a new place for a spot
// and draw it.
mx = (int)(Math.random()*1000) % change;
my = (int)(Math.random()*1000) % change;
g.fillOval(mx, my, radius, radius);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -