while 루프가있는 스레드를 호출하는 게임을 만들려고합니다. 기본적으로 버튼을 누르면 화면을 전환하는 JFrame을 사용하고 있습니다. 나가 얻는 것을 시도하고있는 무엇은, 당신이 단추를 누를 때, 기와를 당기고 그 후에 실을 부른다이다. 그러나 버튼을 누르면 화면이 정지됩니다. 버튼을 누르고 변경되지 않는 화면에 머물러 있습니다. 스레드를 호출하지 않으면 변경됩니다. 또한 while 루프의 위치를 변경하려고 시도 했는데도 작동하지 않았습니다.While 루프를 사용하면 전체 스크립트가 고정됩니다.
추첨 스크립트 :
void loadLevel(String level) {
panel.remove(searchTA);
panel.remove(titleL);
panel.remove(search2B);
panel.repaint();
this.level = level;
int x = 160;
int y = 140;
int tile = 0;
int line = 0;
for (int i = 0; i < 13; i++) {
for (int j = 0; j < 13; j++) {
String formula = (String
.valueOf(readFile("resources/Base Levels/Back Layer/" + level, line).charAt(tile))
+ String.valueOf(readFile("resources/Base Levels/Front Layer/" + level, line).charAt(tile)));
if (formula.equals("00")) {
try {
BufferedImage img;
BufferedImage c;
img = ImageIO.read(clear);
c = resize(img, 50, 50);
JLabel lb = new JLabel(new ImageIcon(c));
lb.setLocation(x, y);
lb.setSize(50, 50);
panel.add(lb);
} catch (IOException e) {
e.printStackTrace();
}
} else if (formula.equals("01")) {
try {
BufferedImage img;
BufferedImage c;
img = ImageIO.read(goal);
c = resize(img, 50, 50);
JLabel lb = new JLabel(new ImageIcon(c));
lb.setLocation(x, y);
lb.setSize(50, 50);
panel.add(lb);
} catch (IOException e) {
e.printStackTrace();
}
} else if (formula.equals("02")) {
try {
BufferedImage img;
BufferedImage c;
img = ImageIO.read(wall);
c = resize(img, 50, 50);
JLabel lb = new JLabel(new ImageIcon(c));
lb.setLocation(x, y);
lb.setSize(50, 50);
panel.add(lb);
} catch (IOException e) {
e.printStackTrace();
}
}
x = x + 50;
tile++;
}
tile = 0;
line++;
x = 160;
y = y + 50;
}
play.run();
}
스레드 :
public Thread play = new Thread(new Runnable() {
public void run() {
panel.revalidate();
panel.repaint();
String tileOn = new String();
String[] tiles = new String[169];
int tile = 0;
for (int i = 1; i < 14; i++) {
for (int b = 1; b < 14; b++) {
tiles[tile] = String
.valueOf(readFile("resources/Base Levels/Back Layer/" + level, i - 1).charAt(b - 1))
+ String.valueOf(readFile("resources/Base Levels/Front Layer/" + level, i - 1).charAt(b - 1));
tile++;
}
}
while (!tileOn.equals("01")) {
}
}
});
내가 동결을 말할 때, 나는 동결 의미한다. JFrame의 오른쪽 상단에있는 X를 눌러도 닫히지 않습니다. Eclipse (IDE)로 돌아가서 스크립트를 중지해야합니다. 또한 while 루프를 제거하려고 시도했기 때문에 while 루프가 문제를 일으킨다는 것을 알고 있습니다.
고정을 취소합니다. – markspace
'tileon'은 어떻게 값을 변경합니까? – VHS
물론 정지 상태 일 때 while 루프에 대한 종료 조건이 없습니다. 타일 "01"에 있지 않으면 while 루프를 종료하기 위해 결국 false가되는 코드를 넣으십시오. – Tyler