我有我的揮杆接口的Java while循環不循環
private void solveButtonMouseClicked(java.awt.event.MouseEvent evt) {
step1();
}
它調用第一步以下按鈕();
private void step1(){
//step 1 solving the white cross around the yellow middle
while((!(F2.getBackground().equals(white))) & (!(F4.getBackground().equals(white))) & (!(F6.getBackground().equals(white))) & (!(F8.getBackground().equals(white)))){
textArea.append("cnt");
//top three pieces solved
if(F2.getBackground().equals(white) && F4.getBackground().equals(white) && F6.getBackground().equals(white)){
//solve F8
while(!(F8.getBackground().equals(white))){
//check right side
if(R2.getBackground().equals(white)){right(); right(); downinv(); rightinv(); rightinv();}
else if(R4.getBackground().equals(white)){rightinv(); downinv(); right();}
else if(R6.getBackground().equals(white)){right(); downinv(); rightinv();}
else if(R8.getBackground().equals(white)){downinv();}
//check left side
else if(L2.getBackground().equals(white)){left(); left(); down(); leftinv(); leftinv();}
else if(L4.getBackground().equals(white)){leftinv(); down(); left();}
else if(L6.getBackground().equals(white)){left(); down(); leftinv();}
else if(L8.getBackground().equals(white)){down();}
//check back side
else if(B2.getBackground().equals(white)){back(); back(); down(); down();}
else if(B4.getBackground().equals(white)){backinv(); down(); down();}
else if(B6.getBackground().equals(white)){back(); down(); down();}
else if(B8.getBackground().equals(white)){down(); down();}
//check up side
else if(U2.getBackground().equals(white)){frontinv(); up(); rightinv(); upinv();}
else if(U4.getBackground().equals(white)){frontinv(); up(); up(); rightinv(); upinv(); upinv();}
else if(U6.getBackground().equals(white)){frontinv(); rightinv();}
else if(U8.getBackground().equals(white)){front();}
//check down side
else if(D2.getBackground().equals(white)){down(); frontinv(); right();}
else if(D4.getBackground().equals(white)){front(); right();}
else if(D6.getBackground().equals(white)){frontinv(); leftinv();}
else if(D8.getBackground().equals(white)){downinv(); frontinv(); right();}
}//end while
}//end if
//top two pieces solved
if(F2.getBackground().equals(white) && F4.getBackground().equals(white)){
//solve F6
while(!(F6.getBackground().equals(white))){
//chech front side
if(F8.getBackground().equals(white)){front();}
//check right side
else if(R2.getBackground().equals(white)){frontinv(); up(); front();}
else if(R4.getBackground().equals(white)){right(); frontinv(); up(); front();}
else if(R6.getBackground().equals(white)){rightinv(); frontinv(); up(); front();}
else if(R8.getBackground().equals(white)){right(); right(); frontinv(); up(); front();}
//check left side
else if(L2.getBackground().equals(white)){frontinv(); upinv(); front();}
else if(L4.getBackground().equals(white)){frontinv(); left(); upinv(); leftinv(); front();}
else if(L6.getBackground().equals(white)){frontinv(); leftinv(); upinv(); left(); front();}
else if(L8.getBackground().equals(white)){frontinv(); left(); left(); upinv(); left(); left(); front();}
//check back side
else if(B2.getBackground().equals(white)){frontinv(); up(); up(); front();}
else if(B4.getBackground().equals(white)){frontinv(); backinv(); up(); up(); front();}
else if(B6.getBackground().equals(white)){frontinv(); back(); up(); up(); front();}
else if(B8.getBackground().equals(white)){frontinv(); back(); back(); up(); up(); front();}
//check up side
else if(U2.getBackground().equals(white)){up();rightinv();upinv();}
else if(U4.getBackground().equals(white)){up(); up();rightinv(); upinv(); upinv();}
else if(U6.getBackground().equals(white)){rightinv();}
else if(U8.getBackground().equals(white)){upinv(); rightinv(); up();}
//check down side
else if(D2.getBackground().equals(white)){down(); right();}
else if(D4.getBackground().equals(white)){down(); down(); right();}
else if(D6.getBackground().equals(white)){right();}
else if(D8.getBackground().equals(white)){downinv(); right();}
}//end while
textArea.append("\nstep 1a (75% complete)\n");
}//end if
//top piece solved
if((F2.getBackground().equals(white)) && (!(F4.getBackground().equals(white)))){
//solve F4
while(!(F4.getBackground().equals(white))){
//check front side
if(F6.getBackground().equals(white)){frontinv();}
//check right side
else if(R2.getBackground().equals(white)){front(); up(); frontinv();}
else if(R4.getBackground().equals(white)){right(); front(); up(); frontinv();}
else if(R6.getBackground().equals(white)){rightinv(); front(); up(); frontinv();}
else if(R8.getBackground().equals(white)){right(); right(); front(); up(); frontinv();}
//check left side
else if(L2.getBackground().equals(white)){front(); upinv(); frontinv();}
else if(L4.getBackground().equals(white)){front(); left(); upinv(); frontinv();}
else if(L6.getBackground().equals(white)){front(); leftinv(); upinv(); frontinv();}
else if(L8.getBackground().equals(white)){front(); left(); left(); upinv(); frontinv();}
//check back side
else if(B2.getBackground().equals(white)){front(); up(); up(); frontinv();}
else if(B4.getBackground().equals(white)){front(); backinv(); up(); up(); frontinv();}
else if(B6.getBackground().equals(white)){front(); back(); up(); up(); frontinv();}
else if(B8.getBackground().equals(white)){front(); back(); back(); up(); up(); frontinv();}
//check up side
else if(U2.getBackground().equals(white)){front(); front(); up(); rightinv(); frontinv(); frontinv();}
else if(U4.getBackground().equals(white)){left();}
else if(U6.getBackground().equals(white)){front(); front(); rightinv(); frontinv(); frontinv();}
else if(U8.getBackground().equals(white)){front(); front(); upinv(); rightinv(); frontinv(); frontinv();}
//check down side
else if(D2.getBackground().equals(white)){downinv(); leftinv();}
else if(D4.getBackground().equals(white)){leftinv();}
else if(D6.getBackground().equals(white)){downinv(); downinv(); leftinv();}
else if(D8.getBackground().equals(white)){down(); leftinv();}
}//end while
textArea.append("\nstep 1a (50% complete)\n");
}//end if
if(!(F2.getBackground().equals(white))){
//solve top piece
while(!(F2.getBackground().equals(white))){
if(F4.getBackground().equals(white)){front();}
else if(F6.getBackground().equals(white)){frontinv();}
else if(F8.getBackground().equals(white)){front(); front();}
//check right side
else if(R2.getBackground().equals(white)){up();}
else if(R4.getBackground().equals(white)){right(); up();}
else if(R6.getBackground().equals(white)){rightinv(); up();}
else if(R8.getBackground().equals(white)){right(); right(); up();}
//check left side
else if(L2.getBackground().equals(white)){upinv();}
else if(L4.getBackground().equals(white)){left(); up();}
else if(L6.getBackground().equals(white)){leftinv(); up();}
else if(L8.getBackground().equals(white)){left(); left(); upinv();}
//check back side
else if(B2.getBackground().equals(white)){up(); up();}
else if(B4.getBackground().equals(white)){backinv(); up(); up();}
else if(B6.getBackground().equals(white)){back(); up(); up();}
else if(B8.getBackground().equals(white)){back(); back(); up(); up();}
//check up side
else if(U2.getBackground().equals(white)){up(); rightinv(); frontinv();}
else if(U4.getBackground().equals(white)){up(); up(); rightinv(); frontinv();}
else if(U6.getBackground().equals(white)){rightinv();frontinv();}
else if(U8.getBackground().equals(white)){upinv(); rightinv(); frontinv();}
//check down side
else if(D2.getBackground().equals(white)){down(); right(); frontinv();}
else if(D4.getBackground().equals(white)){down(); down(); right(); frontinv();}
else if(D6.getBackground().equals(white)){right(); frontinv();}
else if(D8.getBackground().equals(white)){downinv(); right(); frontinv();}
}//end while
textArea.append("\nStep 1a (25% complete)\n");
}//end else
}//end while
}//end step 1
該問題似乎是step1()中最外面的while循環。它應該保持運行,直到所有條件都滿足,但它只是一次迭代後停止,我不知道爲什麼。如果我刪除外部while循環step1()按照它應該通過多次按下按鈕時的每個步驟進行。幫幫我!
你真的需要重新思考你的設計。這也難怪代碼不起作用。 – ChaosPandion
ChaosPandion我知道,剛剛得到了第一個設計模式,gona很快就開始閱讀,但它不回答我的問題 – kokokok