Beruflich Dokumente
Kultur Dokumente
- 20 -
Fernando Berzal
Concurrencia
- 21 -
Fernando Berzal
SwingUtilities.invokeLater()
SWING
== EnventQueue.invokeLater()
AWT
- 22 -
Fernando Berzal
javax.swing.Timer
Cuando lo que queremos es realizar una operacin de forma
peridica, no es necesario que creemos explcitamente una hebra.
Podemos utilizar la clase javax.swing.Timer, que asociaremos
a un ActionListener encargado de realizar la operacin:
Timer timer;
public Animator (int fps)
{
timer = new Timer(1000/fps, this);
}
public void startAnimation()
{
timer.start();
}
public void stopAnimation()
{
timer.stop();
}
public void actionPerformed (ActionEvent e)
{
// Mostrar el siguiente frame
repaint();
}
}
Concurrencia
- 23 -
Fernando Berzal