Professional Documents
Culture Documents
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
1/2
2/2
bot.setText(">");
pause = true;
}else if(str.equals(">")){
pause = false;
notify();
bot.setText("||");
}
//Parar hilo
if(str.equals("Stop")){
stop = true;
bstop.setEnabled(false);
bot.setEnabled(false);
}
49
50
51
52
53
54
55
56
57
58
59
60
61
}
public void run() {
//atrapador de excepciones
try{
while(!stop){
Thread.sleep(10);
//if(hilo==Thread.currentThread()){
//almacenamos en p la posicion del bot
Point p = bot.getLocation();
Dimension dim = this.getContentPane().getSize();
//cambiar valor de posicion de acuerdo a la direcci
62
63
64
65
66
67
68
69
70
71
72
n
p.x += d.x;
p.y += d.y;
//si posicion del objeto llega a los limites cambiar
73
74
75
direccion
if(p.x+lad>dim.width)d.x=-1;
if(p.y+lad>dim.height)d.y=-1;
if(p.x<0)d.x = 1;
if(p.y<0)d.y = 1;
//mover objeto
bot.setLocation(p.x,p.y);
//si el boton pause wait()
synchronized(this) { if(pause)wait(); }
76
77
78
79
80
81
82
83
//}
}
}catch(InterruptedException e){ }
84
85
86
}
public static void main () {
Anima t = new Anima();
t.setBounds(0,0,500,500);
t.setVisible(true);
}
87
88
89
90
91
92
93
22/12/2013 09:58:43 AM