如果執行動作(例如按下按鈕),我該如何平滑移動JButton。這裏是我的例子,但它不propely工作:JButton在動作上的平滑移動
public void actionPerformed(ActionEvent event) {
for(int i = 0; i<50; i++){
ww.button.setLocation(ww.button.getLocation().x+1, ww.button.getLocation().y);//ww is a JFrame child
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
後所執行的操作,我得到的20 * 50毫秒,按鈕位置在以前的LOC + 50像素設置延遲,無中間位置。
嘗試使用佈局。 – 2013-02-28 06:07:54
什麼是ww?你也使用多態爲你的按鈕。你能展示更多的代碼嗎? – RyanDawkins 2013-02-28 06:07:56