运行我的 java 代码可以在调试器中运行,但不能在运行中运行。在 Eclipse 调试器中,它显示了我的 jframe。
但是,当我运行它时,我的框架不会出现。
我相信我搞砸了我的 EventListener 和所有这些。
private class ButtonHandler implements ActionListener{
JButton button;
public void actionPerformed(ActionEvent event) {
find(event.getSource());
button = buttonHolder[indexK[kCount-1]][indexJ[jCount-1]];
if((button.getIcon() == red && choice1 == 1) || (button.getIcon() == green && choice1 == 0)){
JOptionPane.showMessageDialog(null, "You chose the wrong color!");
return;
}
if(turn ==1){
if(clicks != 1){
if(button.getIcon() == red){
clicks++;
temp = button;
}else if (button.getIcon() == green){
clicks++;
temp = button;
}else{
kCount=0;
jCount=0;
}
}else{
if((button.getIcon() == green) || (button.getIcon() == red)){
//do nothing
}else if(temp.getIcon() == green && (grid[indexK[1]][indexJ[1]] == 2 || grid[indexK[1]][indexJ[1]] == 3 || grid[indexK[1]][indexJ[1]] == 4) && button.getIcon() != green && ((indexK[0]+1 ==indexK[1] && indexJ[0] == indexJ[1]) || (indexK[0] ==indexK[1] && indexJ[0]+1 == indexJ[1]) || (indexK[0] ==indexK[1] && indexJ[0]-1 == indexJ[1])) ){
temp.setIcon(null);
button.setIcon(green);
grid[indexK[1]][indexJ[1]] = 2;
if(indexK[0] == 0 || indexK[0]== 9){
grid[indexK[0]][indexJ[0]] = 4;
}else{
grid[indexK[0]][indexJ[0]] =3;
}
found = 2;
}else if(temp.getIcon() == red && (grid[indexK[1]][indexJ[1]] == 1 || grid[indexK[1]][indexJ[1]] == 3 || grid[indexK[1]][indexJ[1]] == 5) && button.getIcon() != red && ((indexK[0]+1 ==indexK[1] && indexJ[0] == indexJ[1]) || (indexK[0] ==indexK[1] && indexJ[0]+1 == indexJ[1]) || (indexK[0]-1 ==indexK[1] && indexJ[0] == indexJ[1]))){
temp.setIcon(null);
button.setIcon(red);
grid[indexK[1]][indexJ[1]] = 1;
if(indexJ[0] == 0 || indexJ[0]== 9){
grid[indexK[0]][indexJ[0]] = 5;
}else{
grid[indexK[0]][indexJ[0]] =3;
}
found = 2;
}
clicks=0;
kCount=0;
jCount=0;
}
}
}
}
}
如果你没有看到任何问题,你能想出它可能会搞砸的原因吗?