[英]Illegal start of expression java slick
我遇到了這個問題,並且它不斷拋出非法的表達式開始,我檢查了方括號,我認為它們很好。 這是代碼:另外,它說在第30行有一個錯誤,我不太了解。
public class Menu extends BasicGameState {
Image playNow;
Image exitGame;
public String mouse = "No Input Yet!";
public Menu(int state) {
}
@Override
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
playNow = new Image("res/playNow.png");
exitGame = new Image("res/exitGame.png");
}
@Override
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
g.drawString(mouse, 590, 10);
g.drawString("Welcome to my Game!", 100, 50);
playNow.draw(100,100);
exitGame.draw(100, 200);
}
//slick counts from the bottom-left of the display, not the top-left, like java does
@Override
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
Input input = gc.getInput();
int mousex = Mouse.getX();
int mousey = Mouse.getY();
mouse = "Mouse coordinate x: " + mousex + " y: " + mousey;
// x-min:105 x-max:300 y-min: y-max:300
if(input.isMouseButtonDown(0)) {
if(mousex>100 && mousex<300) && (mousey>400 && mousey< 435) { //error
sbg.enterState(1);
}
if(mousex>100 && mousex<300) && (mousey>300 && mousey <335) { //error
System.exit(0);
}
}
}
@Override
public int getID() {
return 0;
}
我真的很需要幫助。
在Java中, if
條件必須用括號完全包圍。 更改
if(mousex>100 && mousex<300) && (mousey>400 && mousey< 435) {
至
if((mousex>100 && mousex<300) && (mousey>400 && mousey< 435)) {
......另if
條件類似。
編譯器認為(mousex>100 && mousex<300)
是整個條件,而&& (mousey>400 && mousey< 435)
作為條件的主體沒有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.