Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package game;
- import gui.ActionHandler;
- import gui.Button;
- import gui.GUIManager;
- import gui.TextField;
- import org.newdawn.slick.*;
- import org.newdawn.slick.state.BasicGameState;
- import org.newdawn.slick.state.StateBasedGame;
- /**
- * User: Zsolt
- * Date: 2013.04.21.
- * Time: 15:38
- */
- public class JoinState extends BasicGameState {
- GUIManager guiManager = new GUIManager();
- private int width, height;
- private Button cancelButton, joinButton;
- private TextField ipField;
- @Override
- public int getID() {
- return 2;
- }
- @Override
- public void init(GameContainer gc, final StateBasedGame sbg) throws SlickException {
- final Input input = gc.getInput();
- width = gc.getWidth();
- height = gc.getHeight();
- cancelButton = new Button(width / 2, height / 2 + 60, 200, 50);
- cancelButton.setText("cancel");
- cancelButton.add(new ActionHandler() {
- @Override
- public void pressed() {
- sbg.enterState(new MenuState().getID());
- }
- @Override
- public void hover() {
- cancelButton.setColor(Color.orange);
- }
- @Override
- public void notHover() {
- cancelButton.setColor(Color.gray);
- }
- });
- guiManager.add(cancelButton);
- ipField = new TextField(width / 2, height / 2 - 60, 200, 50);
- ipField.add(new ActionHandler() {
- @Override
- public void pressed() {
- ipField.setFocused(true);
- }
- @Override
- public void hover() {
- }
- @Override
- public void notHover() {
- if (input.isMousePressed(0)) {
- ipField.setFocused(false);
- }
- }
- });
- guiManager.add(ipField);
- joinButton = new Button(width / 2, height / 2, 200, 50);
- joinButton.setText("Join");
- joinButton.add(new ActionHandler() {
- @Override
- public void pressed() {
- }
- @Override
- public void hover() {
- joinButton.setColor(Color.orange);
- }
- @Override
- public void notHover() {
- joinButton.setColor(Color.gray);
- }
- });
- guiManager.add(joinButton);
- }
- @Override
- public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
- cancelButton.render(gc, g);
- ipField.render(gc, g);
- joinButton.render(gc, g);
- g.drawString("IP ADDRESS:", width/2 - g.getFont().getWidth("IP ADDRESS")/2, height/2 - 100);
- }
- @Override
- public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
- Input input = gc.getInput();
- if (width != gc.getWidth()) {
- width = gc.getWidth();
- cancelButton.setX(width / 2);
- ipField.setX(width / 2);
- joinButton.setX(width / 2);
- }
- if (height != gc.getHeight()) {
- height = gc.getHeight();
- cancelButton.setY(height / 2 + 60);
- ipField.setY(height / 2 - 60);
- joinButton.setY(height / 2);
- }
- guiManager.update(gc, delta);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement