私はあるクラス(Welcomeという名前)に "status" JLabelを持っていて、もう1つはTimerという名前のタイマーです。今、最初のものは "ステータス"という単語を表示し、2番目のものはカウントダウンを行うべきです。私はそれが欲しいと思う方法ですが、10、9、8、7 ... 0を表示する方法を知りません(そして次のウィンドウに移動します)。私の試みこれまで:JLabelはカウントダウンを表示しています。
// class Welcome
setLayout(new BorderLayout());
JPanel area = new JPanel();
JLabel status = new JLabel("status");
area.setBackground(Color.darkGray);
Font font2 = new Font("SansSerif", Font.BOLD, 25);
status.setFont(font2);
status.setForeground(Color.green);
area.add(status, BorderLayout.EAST); // can I put it in the bottom-right corner?
this.add(area);
とタイマー:
public class Timer implements Runnable {
// public void runThread() {
// new Thread(this).start();
// }
public void setText(final String text) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setText(text); // link to status here I guess
}
});
}
public void run() {
for (int i = 10; i > 0; i--) {
// set the label
final String text = "(" + i + ") seconds left";
setText(text);
// // sleep for 1 second
// try {
// Thread.currentThread();
// Thread.sleep(1000);
// } catch (Exception ex) {
// }
}
// go to the next window
UsedBefore window2 = new UsedBefore();
window2.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// runThread();
}
} // end class
申し訳ありませんが、最後の文を取得していません。別の言葉でそれを入れてもらえますか? – Hurdler
@Hurdler:編集 –
をどうぞ宜しくお願い致します。私はコードを通過し、それを完了します!再度、感謝します。ところで、頑強な「ステータス」ラベルに関するヒントはありますか? – Hurdler