0
我有一個JLabel。最初我已經爲它設置了一些文本。添加一個計時器,顯示標籤文字
JLabel j = new JLabel();
// set width height and position
j.setText("Hello");
我只希望文本Hello顯示5秒鐘。那麼我想要顯示文字再見。
我怎麼能做到這一點。
我的工作方式;但我知道這是錯的,因爲它一次只能執行1的if-else塊。我想我需要一個計時器或一個計數器。得到這個工作。幫幫我 ?
long time = System.currentTimeMillis();
if (time < (time+5000)) { // adding 5 sec to the time
j.setText("Hello");
} else {
j.setText("Bye");
}
+1很好的例子 –