Montag, 8. Dezember 2008

EE3206/EE5805 java Thread animations

EE3206/EE5805 Java programming and Application

notes on Liang(2009), p.964

use a thread to control animations


import javax.swing.*;


public class FlashingText extends JApplet implements Runnable
{
private JLabel jlblText = new JLabel("DMC Welcome", JLabel.CENTER);

public FlashingText()
{
add(jlblText);
new Thread(this).start();
}

public void run()
{
try
{
while(true)
{
if (jlblText.getText() == null)
jlblText.setText("DMC Welcome");
else
jlblText.setText(null);

Thread.sleep(300); // static
} // end while

}
catch(InterruptedException e)
{

}
}
}




Keine Kommentare: