我正在尝试制作一个程序,当用户单击它时,它会获得坐标并按时间将该矩形移动到该坐标,我正在尝试学习的是如何在移动时打勾 (我没有上课,我只需要知道如何做到这一点)
最佳答案
您可能希望使用 Timer 和 TimerTask 每隔一秒左右移动一次矩形。
示例:
public class Reminder {
Timer timer;
public Reminder(int seconds) {
timer = new Timer();
timer.schedule(new RemindTask(), seconds * 1000);
}
class RemindTask extends TimerTask {
public void run() {
System.out.format("Time's up!%n");
timer.cancel(); //Terminate the timer thread
}
}
public static void main(String args[]) {
new Reminder(5);
System.out.format("Task scheduled.%n");
}
}
关于java 如何让一个矩形随时间移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34113787/