-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlyingBoll.java
More file actions
49 lines (44 loc) · 968 Bytes
/
FlyingBoll.java
File metadata and controls
49 lines (44 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.awt.*;
public class FlyingBoll {
public static void main(String arg[]){
Frame fm = new Frame();
fm.setSize(1368, 768);
fm.setBackground(Color.blue);
MyPanel css = new MyPanel();
fm.add(css);
Thread t = new Thread(css); //建立线程
t.start(); //此时的线程处于就绪状态,随时等待CPU的轮转调度
fm.show();
System.out.println("Hello~");
}
}
class MyPanel extends Panel implements Runnable{
int x = 300;
int y = 100;
public void paint(Graphics G){
G.setColor(Color.WHITE);
G.fillOval(x, y, 50, 50);
/* int x=300,y=100;
while(y<700){
G.setColor(Color.WHITE);
G.fillOval(x, y, 50, 50);
//G.setColor(Color.blue);
G.fillOval(x, y, 50, 50);
//x=x+3;
y=y+3;
}*/
}
public void run(){
while(true){
y++;x++;
if(y>600 || x>1000){
y = 10;
x = 10;
}
try{
Thread.sleep(10);
}catch(Exception e){}
repaint(); //发出repaint的系统调用,系统见到后会调用paint,进行重画操作;
}
}
}