I've problems re-executing the repaint (), I can rotate the image but when I stop it (setRuletaGirando (false)) and change the value of the previous method to true, it does not rotate again.
paint the image and rotate this
public void paintComponent(Graphics g) {
// se cargan las imagenes
BufferedImage ruleta = cargarImagen("src/imagenes/Ruleta.png");
BufferedImage flecha = cargarImagen("src/imagenes/Flecha.png");
//posicion en la que se ubicara la imagen a rotar
AffineTransform at = AffineTransform.getTranslateInstance(50, 50);
//el metodo posiciones devuelve el entero (angulo) en la posicion iteradorimagen ,
at.rotate(Math.toRadians(posiciones(iteradorImagen++)),ruleta.getWidth()/2,ruleta.getHeight()/2);
Graphics2D ruleta2D=(Graphics2D) g;
ruleta2D.setColor(Color.GREEN.darker());
ruleta2D.fillRect(0, 0, this.getWidth(), this.getHeight());
ruleta2D.drawImage(ruleta, at, null);
ruleta2D.drawImage(flecha, 275, 85,50,50,this);
// este metodo propio de la clase graphics2D es el que refresca el panel y
//"hace girar la imagen"(repaint)
if(ruletaGirando) {
repaint();
}
}
}
}
Method with the problem
public void initGUI() {
ruleta = new PanelRuleta();
this.add(ruleta);
Thread t = new Thread(){
public synchronized void run() {
try{
ruleta.setRuletaGirando(true);
Thread.sleep(4000);
ruleta.setRuletaGirando(false);
Thread.sleep(100);
ruleta.setRuletaGirando(true);
}catch(InterruptedException e){}
}
};
t.start();
}
}
You will have to invoke the repaint() method again. Otherwise the paintComponent method won't be called.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.