문제 설명
Java 시간에 따라 사각형을 이동하는 방법 (java how to make a rectangle move by time)
저는 사용자가 클릭할 때 좌표를 얻고 사각형을 시간별로 좌표로 이동하는 프로그램을 만들려고 합니다. 내가 배우려고 하는 것은 움직일 때 눈금을 만드는 방법입니다(나는 단지 필요한 클래스를 만들지 않았습니다. 그 방법에 대한 아이디어를 알기 위해)
참조 솔루션
방법 1:
You would probably want to use a Timer and a TimerTask to move the rectangle every second or so.
Example:
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");
}
}
(by Heroxlegend、Connor Christie)