질문하기 전에 불일치에 대해 사과드립니다. 나는 이것에 상당히 새로운 것이다. 지금은 (사진은 중요하지 않다)이 같다고 게임을 미안은 : 타이머가있는 도트의 그래픽 업데이트
빨간 점은 오른쪽으로 이동하기로하고 타이머로 그렇게하고 있습니다. 이것은 잘 작동합니다. 그래도 그래픽이 업데이트되지 않으므로 윈도우의 측면을 앞뒤로 드래그하여 점들이 움직이는 것을 확인해야합니다. 이 문제를 해결하려면 어떻게해야합니까? 내 mainclass에서
내의 paintComponent 방법 :
public void paintComponent(Graphics g){
super.paintComponent(g);
for (int x = 0; x < SomeInts.amount; x++){
for (int y = 0; y < SomeInts.amount; y++){
tile[x][y].colorBody(g, x, y);
Tower temp;
for (int i = 0; i < towers.size(); i++){
temp = towers.get(i);
temp.colorBody(g, tile[x][y].getSize());
temp.guard.colorBody(g, tile[x][y].getSize());
}
}
}
}
내 레드 닷 클래스입니다. 또한라는 가드 클래스 :
public class Guard {
int x, y, size = 10, towerx, towery;
Timer timer;
public Guard(int towerx1, int towery1){
towerx = towerx1;
towery = towery1;
x = towerx + 1;
y = towery;
new Timer().schedule(new MyTask(), 1000, 1000);
}
public void colorBody(Graphics g, int tilesize){
g.setColor(new Color(255, 0, 0));
g.fillOval(x * tilesize + tilesize/4, y * tilesize + tilesize/4, size, size);
}
public class MyTask extends TimerTask {
public void run() {
x++;
}
}
}
는 시간 내 주셔서 감사합니다.
가능성이있는 이유는 EDT를 업데이트하는 것입니다. 스윙을 사용하십시오. util 버전이 아닙니다. – kleopatra
이 예를 들어 주시겠습니까? 같은 방식으로 작동하지 않는 것 같습니다. –
@ ZachariasHortén : [튜토리얼] (http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html)을 참조하십시오. –