0
화면에 프레임을 임의로 설정하는 타이머를 설정하려고 시도했지만 그 다음에 boolean
에 따라 다시 정상으로 설정하십시오. 이미 .cancel()
시도했지만 작동하지 않습니다. 지금은이 타이머?게임 타이머가 멈추지 않습니다.
if(e.getSource()==impossible){
impossiblity=!impossiblity;
System.out.println(impossiblity);
if(!impossiblity){
new Timer().schedule(new TimerTask() {
public void run() {
int randWidth=(int)((dim.width-gameFrame.getSize().width) * Math.random());
int randHeight=(int)((dim.height-gameFrame.getSize().height) * Math.random());
gameFrame.setLocation(randWidth, randHeight);//sets location to center
}
}, 1000, 1000);
} else gameFrame.setLocation(dim.width/2-gameFrame.getSize().width/2, 0);//sets Location to center of screen
}
을 막을 수는 다시 정상으로 gameframe를 설정 않지만 다음 스레드가 외부에서 타이머 또는 다른 스레드를 취소하려고 일반적으로
처음에는 두 가지 부울이 있는데, '불가능'과 '불가능'으로 나타납니다. – Makoto
죄송합니다. 나는 그 것을 포함하지 않았습니다. – user3063455
(거의) 무엇이든 Swing 'Timer'를 사용하는 것이 더 낫습니다. GUI와 관련이있다. 더 빨리 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –