Re: [問題] 讓Swing稍微停頓一下
來報告一下我解決的辦法
後來我放棄用JButton.setIcon
繼承JButton,直接自己畫
大概概念如下
class MyButton extends JButton{
public draw2Pic(){
Graphics g = this.getGraphics();
icon1.paintIcon(this, g, 0, 0);
try{ Thread.sleep(1000);}catch(Exception e){}
icon2.paintIcon(this, g, 0, 0 );
}
}
然後每次要用的時候就呼叫MyButton.draw2Pic()
到目前都很順利XD
※ 引述《chchwy (mat)》之銘言:
: 請問
: 我寫一個Swing程式
: 有個JButton我想讓他被按下去的時候
: 先顯示一張圖按,過一秒,再顯示另一張圖案
: 概念大概如下
: actionPerformed(ActionEvent e){
: if(e.getSource()==button1){
: button1.setIcon(icon1);
: //這裡停頓一秒
: button1.setIcon(icon2);
: }
: }
: 請問要怎麼做比較好?
: 我有試著在中間插入 Thread.sleep(1000);
: 結果第一張圖完全沒影兒,
: 停了一秒後直接跑第二張圖出來
: 我翻過API,要做到這個功能一定要用Swing.Timer嗎?
: 先謝過各位了<(_ _)>
--
夜精小德 Char - 巨龍之喉 (前月神殿) PvP
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.68.15.209
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):