Java:迷宫图标:怎么办?
我在爪哇是个十足的笨蛋。我仍然真的不知道如何编码。 我的迷宫有问题。我现在可以从开始(2)转到结束(3),但问题是(开始)的图标。我试着打印出迷宫(mazePlan)的值,结果很好。唯一的问题是图标。图标只有在递归函数完成后才会更改(我使用了setIcons)。我需要得到这些图标开始移动。谢谢我真的需要一些帮助。谢谢Java:迷宫图标:怎么办?,java,Java,我在爪哇是个十足的笨蛋。我仍然真的不知道如何编码。 我的迷宫有问题。我现在可以从开始(2)转到结束(3),但问题是(开始)的图标。我试着打印出迷宫(mazePlan)的值,结果很好。唯一的问题是图标。图标只有在递归函数完成后才会更改(我使用了setIcons)。我需要得到这些图标开始移动。谢谢我真的需要一些帮助。谢谢 class solveButton implements ActionListener{ private boolean goal; public void ac
class solveButton implements ActionListener{
private boolean goal;
public void actionPerformed(ActionEvent e1)
{
int i,j, a = 0,b = 0;
goal = false;
//Find 2/start
for(i = 0; i<10; i++){
for ( j = 0; j<10; j++){
if (getMazePlan()[i][j] == 2){
a= i; b = j;
}
}
}
function(a,b);
//print only
for (i=0;i<10;i++){
for(j = 0; j < 10; j++){
System.out.print(getMazePlan()[i][j] + " ");
}
System.out.println();
}
}
public void function(int y, int x){
int ctr = 0,b ,a;
//CHECKING FOR WALLS
//LEFT
if(x-1 >= 0 && x-1 <= 9){
if(getMazeBoolean()[y][x-1] == false)
ctr++;
}
//UP
if(y-1 >= 0 && y-1 <= 9){
if(getMazeBoolean()[y-1][x] == false)
ctr++;
}
//RIGHT
if(x+1 >= 0 && x+1 <= 9){
if(getMazeBoolean()[y][x+1] == false)
ctr++;
}
//DOWN
if(y+1 >= 0 && y+1 <= 9){
if(getMazeBoolean()[y+1][x] == false)
ctr++;
}
try{
Thread.sleep(1000);
}catch(Exception e){}
//print only
System.out.println("Move");
for (int i=0;i<10;i++){
for(int j = 0; j < 10; j++){
System.out.print(getMazePlan()[i][j] + " ");
}
System.out.println();
}
stack1.push(x);
stack1.push(y);
setMazePlan1(0, y, x);
maze[y][x].setIcon(end);
setMazeBoolean(true, y , x);
//LEFT
if(ctr > 0 && goal == false){
if(x-1 >= 0 && x-1 <= 9){
if(getMazeBoolean()[y][x-1] == false && getMazePlan()[y][x-1] != 3){
setMazePlan1(2, y, x-1);
function(y, x-1);
ctr--;
if(ctr != 0 && goal == false){
b = stack1.pop();
a = stack1.pop();
setMazePlan1(2, b , a);
stack1.push(a);
stack1.push(b);
try{
Thread.sleep(1000);
}catch(Exception e){}
setMazePlan1(0, b , a);
}
}
else if(getMazePlan()[y][x-1] == 3){
System.out.println("FINISH");
goal = true;
}
}
}
//UP
if(ctr > 0 && goal == false){
if(y-1 >= 0 && y-1 <= 9){
if(getMazeBoolean()[y-1][x] == false && getMazePlan()[y-1][x] != 3){
setMazePlan1(2, y-1, x);
function(y-1, x);
ctr--;
if(ctr != 0 && goal == false){
b = stack1.pop();
a = stack1.pop();
setMazePlan1(2, b , a);
stack1.push(a);
stack1.push(b);
try{
Thread.sleep(1000);
}catch(Exception e){}
setMazePlan1(0, b , a);
}
}
else if(getMazePlan()[y-1][x] == 3){
System.out.println("FINISH");
goal = true;
}
}
}
//RIGHT
if(ctr > 0 && goal == false){
if(x+1 >= 0 && x+1 <= 9){
if(getMazeBoolean()[y][x+1] == false && getMazePlan()[y][x+1] != 3 ){
setMazePlan1(2, y, x+1);
function(y, x+1);
ctr--;
if(ctr != 0 && goal == false){
b = stack1.pop();
a = stack1.pop();
setMazePlan1(2, b , a);
stack1.push(a);
stack1.push(b);
try{
Thread.sleep(1000);
}catch(Exception e){}
setMazePlan1(0, b , a);
}
}
else if(getMazePlan()[y][x+1] == 3){
System.out.println("FINISH");
goal = true;
}
}
}
//DOWN
if(ctr > 0 && goal == false){
if(y+1 >= 0 && y+1 <= 9){
if(getMazeBoolean()[y+1][x] == false && getMazePlan()[y+1][x] != 3){
setMazePlan1(2, y+1, x);
function(y+1, x);
ctr--;
if(ctr != 0 && goal == false){
b = stack1.pop();
a = stack1.pop();
setMazePlan1(2, b , a);
stack1.push(a);
stack1.push(b);
try{
Thread.sleep(1000);
}catch(Exception e){}
setMazePlan1(0, b , a);
}
}
else if(getMazePlan()[y+1][x] == 3){
System.out.println("FINISH");
goal = true;
}
}
}
//DEADEND
if(goal == false && ctr == 0){
b = stack1.pop();
a = stack1.pop();
setMazePlan1(0, b , a);
try{
b = stack1.pop();
a = stack1.pop();
stack1.push(a);
stack1.push(b);
setMazePlan1(2, b , a);
}
catch(Exception e){
}
try{
Thread.sleep(1000);
}catch(Exception e){}
//print only
System.out.println("Pop");
for (int i=0;i<10;i++){
for(int j = 0; j < 10; j++){
System.out.print(getMazePlan()[i][j] + " ");
}
System.out.println();
}
}
}
}
class solveButton实现ActionListener{
私有布尔目标;
已执行的公共无效操作(操作事件e1)
{
int i,j,a=0,b=0;
目标=错误;
//查找2/开始
对于(i=0;i=0&&x+10&&goal==false){
如果(y+1>=0&&y+1而不尝试破译hauge代码块,则在设置图标后,听起来需要强制重新绘制/绘制
实际上,这里没有足够的代码来知道如何调用repaint()
您可能还想看看Java GUI应用程序/GUI线程(即,如果可能需要一段时间,您不应该在GUI线程上执行所有“迷宫”操作)如果不尝试破译您的hauge代码块,听起来似乎需要在设置图标后强制重新绘制/绘制
实际上,这里没有足够的代码来知道如何调用repaint()
您可能还想看看Java GUI应用程序/GUI线程(即,如果可能需要一段时间,您不应该在GUI线程上执行所有“迷宫”操作)不要阻止EDT(事件调度线程)-发生这种情况时,GUI将“冻结”。而不是调用
Thread.sleep(n)
为重复任务实施Swing计时器
,或为长时间运行的任务实施SwingWorker
。
有关更多详细信息,请参阅。不要阻止EDT(事件调度线程)-发生这种情况时,GUI将“冻结”。而不是调用
Thread.sleep(n)
为重复任务实施Swing计时器
,或为长时间运行的任务实施SwingWorker。
有关更多详细信息,请参阅。为代码感到抱歉…尝试重新绘制图标、面板和框架,但仍不起作用。为代码感到担忧…尝试重新绘制图标、面板和框架,但仍不起作用。我阅读了有关Swing Timer的文章,并尝试使用它。它起作用了!:)是的!非常感谢你这么晚才回复。我读到了关于摆动计时器的文章,并尝试使用它。它很有效!:)是的!非常感谢你