Problema con un bucle while en un boton
Publicado por Jensel Stiven (3 intervenciones) el 25/03/2018 15:12:50
Buenas a todos, estoy programando una pequeña aplicacion que debe mostrarme una animacion de stopmotion, Usando 16 imagenes mostradas por segundo. Pero al reproducirla se bloquea el programa y no muestra ninguna imagen, ademas no puedo manipular los demas componentes de la ventana. Debo cerrarla cancelando el proceso, ¿que debo hacer?
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public void actionPerformed(ActionEvent arg0) {
AnimationControl = true; //Controla la reproduccion
if(SelectAnimation.getSelectedItem() == "Jinete Montando Caballo") { // Si la animacion Seleccionada es jinete montando caballo (16 Frames)
String Path1 = "/ImagenesCaballo/Frame1.jpg" ;
java.net.URL ImageDirection = this.getClass().getResource(Path1); // Lee la imagen 1
ImageIcon Frame1 = new ImageIcon(ImageDirection);
String Path2 = "/ImagenesCaballo/Frame2.jpg" ;
java.net.URL ImageDirection2 = this.getClass().getResource(Path2); // Lee la imagen 2
ImageIcon Frame2 = new ImageIcon(ImageDirection2);
String Path3 = "/ImagenesCaballo/Frame3.jpg" ;
java.net.URL ImageDirection3 = this.getClass().getResource(Path3); // Lee la imagen 3
ImageIcon Frame3 = new ImageIcon(ImageDirection3);
String Path4 = "/ImagenesCaballo/Frame4.jpg" ;
java.net.URL ImageDirection4 = this.getClass().getResource(Path4); // Lee la imagen 4
ImageIcon Frame4 = new ImageIcon(ImageDirection4);
while(AnimationControl) { // Bucle Que establece cada frame por sgundo
Cuadro.setIcon(Frame1); // Establece Frame 1
try {
Thread.sleep(1000);
} catch (InterruptedException e) { //Espera 1 Segundo
e.printStackTrace();
}
Cuadro.setIcon(Frame2);// Establece Frame 2
try {
Thread.sleep(1000);
} catch (InterruptedException e) { //Espera 1 Segundo
e.printStackTrace();
}
Cuadro.setIcon(Frame3); // Establece Frame 3
try {
Thread.sleep(1000);
} catch (InterruptedException e) { //Espera 1 Segundo
e.printStackTrace();
}
Cuadro.setIcon(Frame4); //Establece Frame 4
try {
Thread.sleep(1000);
} catch (InterruptedException e) { //Espera 1 Segundo
e.printStackTrace();
}
}
}
}
Valora esta pregunta


0