點樣用JAVA的sleep

2008-02-29 1:52 am
螢幕中間有個小圈,用滑鼠點到邊,個小圈以每秒10pixels走去個度,中途點去另一度佢識轉向,點用JAVA寫,急

回答 (1)

2008-02-29 2:55 am
✔ 最佳答案
你可以用sleep() 去做個animation,我假設你有vector 呢個 idea :
public void draw_circle() {
// compute the direction to move and store in a Point object
// adjust that Point object so that its length is 10 pixels
// compute the new center of the circle
// draw that circle according to the new center
}
public void update_display() {
while (1) {
// clear the screen
if (!circle.center() .equals(mouse_current_pos)) draw_circle();
sleep(1000); // 1000ms = 1s
}
}
public void mouseMoved(MouseEvent e) {
mouse_current_pos = e.getPoint();
}
我相信你會知o的method 放係邊
圖片參考:http://tw.yimg.com/i/tw/ugc/rte/smiley_1.gif
。你應該要用到MouseMotionListener 呢個Class,你可以去JavaDoc 睇睇點用。


收錄日期: 2021-04-13 15:12:57
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080228000051KK01646

檢視 Wayback Machine 備份