/* @description: 閃滅文字
* @source: Introduction to Java Programming Sixth Edition,Y.DANIEL LIANG
* @chapter: MultiThreading, p.806
**/
import java.awt.*;
import javax.swing.*;
public class FlashingText extends JFrame implements Runnable {
public static final String welcomeMessage = "Welcome to WindFlyer\'s CyberSpace.";
private JLabel lblText = new JLabel(welcomeMessage);
Container contentPane;
public FlashingText() {
super("FlashingText Demo");
contentPane = getContentPane();
contentPane.add(lblText);
}
public void run() {
try {
while(true) {
if(lblText.getText() == null) {
lblText.setText(welcomeMessage);
}else {
lblText.setText(null);
}
Thread.sleep(370);
}
}catch(InterruptedException iE) {
iE.printStackTrace();
}
}
public static void main(String args[]) {
FlashingText text = new FlashingText();
text.setSize(225 , 100);
text.setLocation(300 , 300);
text.setVisible(true);
text.setResizable(false);
text.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Thread flashThread = new Thread(text);
flashThread.start();
}
}
FlashingText.java閃滅文字
Labels: Java程式範例 |
Subscribe to:
Post Comments (Atom)

1 comments:
Considering the fact that it could be more accurate in giving informations.
Post a Comment