我已經動畫了我的一些程序,它是一個移動的人,它的工作原理和一切。我有很多重複的代碼,所以我想試着讓它更有效率,並循環重複。我的問題是,即使支架適量它給我的錯誤下面編譯器錯誤使用循環,開關和案例
public void DrawAstronaut(Graphics2D g2d) {
if (nViewDX == -1) {
DrawAstronautLeft(g2d);
} else if (nViewDX == 1) {
DrawAstronautRight(g2d);
} else {
DrawAstronautStand(g2d);
}
}
public void DrawAstronautLeft(Graphics2D g2d) {
switch (nAstroAnimPos) {
for(int i = 1; i <= 6; i++){
case i:
g2d.drawImage(arimgAstroWalkLeft[i], nAstronautX + 1, nAstronautY + 1, this);
break;
default:
g2d.drawImage(imgAstroStandLeft, nAstronautX + 1, nAstronautY + 1, this);
break;
}
}
}
public void DrawAstronautRight(Graphics2D g2d) {
switch (nAstroAnimPos) {
for(int i = 1; i <= 6; i++){
case i:
g2d.drawImage(arimgAstroWalkRight[i], nAstronautX + 1, nAstronautY + 1, this);
break;
default:
g2d.drawImage(imgAstroStandRight, nAstronautX + 1, nAstronautY + 1, this);
break;
}
}
}
public void DrawAstronautStand(Graphics2D g2d) {
switch (nAstroAnimPos) {
default:
g2d.drawImage(imgAstroStandLeft, nAstronautX, nAstronautY, this);
break;
}
}
幾乎所有的東西當我加入for循環的DrawAstronautLeft下面的一切了錯誤,它甚至不喜歡在公共無效DrawAstronautRight即使他們不應該有任何問題。我知道我有適量的括號,但有人可以幫助把事情放在正確的地方?
的錯誤包括: 不能夠找到符號 「的情況下,默認情況下,或‘}’預期」 「類,接口,或枚舉預期」
始終複製/粘貼錯誤和異常輸出。我認爲你需要圍繞整個switch語句的循環。 –
你的'switch-case'是多餘的..好吧..它總是'我'.... – Maroun
因此,將開關放在for循環中,除了「case i:」之外的所有錯誤,謝謝@ AndrewThompson – BlueBarren