Java 鼠标悬停在区域上,以便进行二维扫描?

Java 鼠标悬停在区域上,以便进行二维扫描?,java,mouseover,slick,Java,Mouseover,Slick,我在谷歌上找不到答案,但是对于Slick2D,是否有鼠标悬停在区域上?谷歌只给了我Java的mouseoverea的结果。我只是想知道是否有Slick2D的mouseoverea,以及它的外观 这是我的代码: import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.Image; import org.newdawn.slick.SlickExceptio

我在谷歌上找不到答案,但是对于
Slick2D
,是否有
鼠标悬停在区域上?谷歌只给了我
Java
mouseoverea
的结果。我只是想知道是否有
Slick2D
mouseoverea
,以及它的外观

这是我的代码:

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class SplashScreen extends BasicGameState {
Image splash;

private int elapsedTime;
private final int DELAY = 3000;

public SplashScreen(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
    splash = new Image("res/SplashScreen.png");

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
    g.drawImage(splash, 0, 0);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(1);
    }
}

public int getID() {
    return 0;
}

}
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Menu extends BasicGameState {

public Menu(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Background.png");
    g.drawImage(background, 0, 0);

    Image logo = new Image("res/Logo.png");
    g.drawImage(logo, 275, 50);

    Image playButton = new Image("res/Play button.png");
    g.drawImage(playButton, 210, 250);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {     

    Input input = gc.getInput();
    int xpos = Mouse.getX();
    int ypos = Mouse.getY();


    if ((xpos > 300 && xpos < 510) && (ypos > 230 && ypos < 260)) {

        if (input.isMousePressed(0)) {
            sbg.enterState(2);
        }
                    //I want to put the Slick2D MouseOverArea code here...
                    //So then when I put the mouse over the playButton, something will display.
    }
}

public int getID() {
    return 1;
}

}
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Loading extends BasicGameState {

private int elapsedTime;
private final int DELAY = 5000;

public Loading(int state) {
}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Back.png");
    g.drawImage(background, 0, 0);

    Image loading = new Image("res/Loading.png");
    g.drawImage(loading, 210, 150);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(3);
    }
}
public int getID() {
    return 2;
}

}
游戏
课程

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Game extends StateBasedGame {

public static final String gamename = "Life - Alpha";
public static int splash = 0;
public static int menu = 1;
public static int loading = 2;
public static int play= 3;

public Game(String gamename) {
    super(gamename);
}

public void initStatesList(GameContainer gc) throws SlickException {
    this.addState(new SplashScreen (splash));
    this.addState(new Menu (menu));
    this.addState(new Exit (exit));
    this.addState(new Loading (loading));
    this.addState(new Play(play));
    this.enterState(0);
}

public static void main(String[] args) {

    AppGameContainer app;
    try {
        app = new AppGameContainer(new Game(gamename));
        app.setDisplayMode(800, 600, false);
        app.start();
    } catch (SlickException e) {
        e.printStackTrace();
    }

}
}
SplashScreen
class:

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class SplashScreen extends BasicGameState {
Image splash;

private int elapsedTime;
private final int DELAY = 3000;

public SplashScreen(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
    splash = new Image("res/SplashScreen.png");

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
    g.drawImage(splash, 0, 0);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(1);
    }
}

public int getID() {
    return 0;
}

}
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Menu extends BasicGameState {

public Menu(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Background.png");
    g.drawImage(background, 0, 0);

    Image logo = new Image("res/Logo.png");
    g.drawImage(logo, 275, 50);

    Image playButton = new Image("res/Play button.png");
    g.drawImage(playButton, 210, 250);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {     

    Input input = gc.getInput();
    int xpos = Mouse.getX();
    int ypos = Mouse.getY();


    if ((xpos > 300 && xpos < 510) && (ypos > 230 && ypos < 260)) {

        if (input.isMousePressed(0)) {
            sbg.enterState(2);
        }
                    //I want to put the Slick2D MouseOverArea code here...
                    //So then when I put the mouse over the playButton, something will display.
    }
}

public int getID() {
    return 1;
}

}
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Loading extends BasicGameState {

private int elapsedTime;
private final int DELAY = 5000;

public Loading(int state) {
}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Back.png");
    g.drawImage(background, 0, 0);

    Image loading = new Image("res/Loading.png");
    g.drawImage(loading, 210, 150);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(3);
    }
}
public int getID() {
    return 2;
}

}
菜单
类:

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class SplashScreen extends BasicGameState {
Image splash;

private int elapsedTime;
private final int DELAY = 3000;

public SplashScreen(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
    splash = new Image("res/SplashScreen.png");

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
    g.drawImage(splash, 0, 0);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(1);
    }
}

public int getID() {
    return 0;
}

}
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Menu extends BasicGameState {

public Menu(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Background.png");
    g.drawImage(background, 0, 0);

    Image logo = new Image("res/Logo.png");
    g.drawImage(logo, 275, 50);

    Image playButton = new Image("res/Play button.png");
    g.drawImage(playButton, 210, 250);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {     

    Input input = gc.getInput();
    int xpos = Mouse.getX();
    int ypos = Mouse.getY();


    if ((xpos > 300 && xpos < 510) && (ypos > 230 && ypos < 260)) {

        if (input.isMousePressed(0)) {
            sbg.enterState(2);
        }
                    //I want to put the Slick2D MouseOverArea code here...
                    //So then when I put the mouse over the playButton, something will display.
    }
}

public int getID() {
    return 1;
}

}
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Loading extends BasicGameState {

private int elapsedTime;
private final int DELAY = 5000;

public Loading(int state) {
}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Back.png");
    g.drawImage(background, 0, 0);

    Image loading = new Image("res/Loading.png");
    g.drawImage(loading, 210, 150);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(3);
    }
}
public int getID() {
    return 2;
}

}
播放
课程:

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class SplashScreen extends BasicGameState {
Image splash;

private int elapsedTime;
private final int DELAY = 3000;

public SplashScreen(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
    splash = new Image("res/SplashScreen.png");

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
    g.drawImage(splash, 0, 0);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(1);
    }
}

public int getID() {
    return 0;
}

}
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Menu extends BasicGameState {

public Menu(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Background.png");
    g.drawImage(background, 0, 0);

    Image logo = new Image("res/Logo.png");
    g.drawImage(logo, 275, 50);

    Image playButton = new Image("res/Play button.png");
    g.drawImage(playButton, 210, 250);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {     

    Input input = gc.getInput();
    int xpos = Mouse.getX();
    int ypos = Mouse.getY();


    if ((xpos > 300 && xpos < 510) && (ypos > 230 && ypos < 260)) {

        if (input.isMousePressed(0)) {
            sbg.enterState(2);
        }
                    //I want to put the Slick2D MouseOverArea code here...
                    //So then when I put the mouse over the playButton, something will display.
    }
}

public int getID() {
    return 1;
}

}
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Loading extends BasicGameState {

private int elapsedTime;
private final int DELAY = 5000;

public Loading(int state) {
}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Back.png");
    g.drawImage(background, 0, 0);

    Image loading = new Image("res/Loading.png");
    g.drawImage(loading, 210, 150);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(3);
    }
}
public int getID() {
    return 2;
}

}
我还在努力。。。但是这个类不需要
鼠标平均区域
,而
菜单
需要


这就是我上面的代码。我只需要一个
mouseoverea
用于
Slick2D
。谷歌没有帮助。希望你能

另外,能否在
Slick2D
中设置
TextField
?我不知道我能不能。我知道在普通的
Java
中你可以,但是在
Slick2D
中你可以吗

如果有任何错误,请不要担心,我可以修复它们。


谢谢

代码不是放在这里了吗

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Game extends StateBasedGame {

public static final String gamename = "Life - Alpha";
public static int splash = 0;
public static int menu = 1;
public static int loading = 2;
public static int play= 3;

public Game(String gamename) {
    super(gamename);
}

public void initStatesList(GameContainer gc) throws SlickException {
    this.addState(new SplashScreen (splash));
    this.addState(new Menu (menu));
    this.addState(new Exit (exit));
    this.addState(new Loading (loading));
    this.addState(new Play(play));
    this.enterState(0);
}

public static void main(String[] args) {

    AppGameContainer app;
    try {
        app = new AppGameContainer(new Game(gamename));
        app.setDisplayMode(800, 600, false);
        app.start();
    } catch (SlickException e) {
        e.printStackTrace();
    }

}
}
if ((xpos > 300 && xpos < 510) && (ypos > 230 && ypos < 260)) {
        //mouseover
        if (input.isMousePressed(0)) {
            sbg.enterState(2);
        }

    }
}
if((xpos>300&&xpos<510)和(ypos>230&&ypos<260)){
//鼠标盖
如果(输入。按下(0)){
进入状态(2);
}
}
}

Welcome to the site'您是否介意编辑您的答案,使其更像一个答案而不是一个问题?