title: Textfield in Slick2D with BasicGameState does not answer
body: <p>I'm currently developing a simple multiplayer game with Slick2D in Java. It's going to be a little more complex with the menu structure because I need several textfields to get the information which server address to connect, how many players are allowed to play, nickname and so on. </p>
  
  <p>I reproduced my problem in 3 classes: The main class (<code>ExampleGame</code>) extends from <code>StateBasedGame</code>, <code>Play</code> and <code>Menu</code> from <code>BasicGameState</code>.</p>
  
  <p>The classes <code>Play</code> and <code>Menu</code> have each one textfield and one button. My problem is I can only type in one of these classes into a textfield. The other textfield doesn't show any cursor responses when you click into the textfield.</p>
  
  <p>This is the main class ExampleGame:</p>
  
  <pre><code>public class ExampleGame extends StateBasedGame  {
  
  public static final int MAIN_MENU_STATE = 0;
  public static final int GAME_PLAY_STATE = 1;
  
  public ExampleGame(String name) {
      super(name);
  
      this.addState(new Menu(MAIN_MENU_STATE));
  this.addState(new Play(GAME_PLAY_STATE));
  
  this.enterState(MAIN_MENU_STATE);
  }
  
  /**
   * @param args
   */
  public static void main(String[] args) {
       AppGameContainer appgc;
   try{
      appgc = new AppGameContainer(new ExampleGame("ExampleGame"));
      appgc.setDisplayMode(640, 360, false);
      appgc.setTargetFrameRate(50);
      appgc.start();
   }catch(SlickException e){
      e.printStackTrace();
   }
  }
  
  @Override
  public void initStatesList(GameContainer arg0) throws SlickException {
      // TODO Auto-generated method stub
      this.getState(GAME_PLAY_STATE);
      this.getState(MAIN_MENU_STATE);
  
  
  System.out.println(this.getStateCount() + ", " + this.getCurrentStateID());
  this.enterState(MAIN_MENU_STATE);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>ExampleGame automatically calls the MainMenu (Menu.java):</p>
  
  <pre><code>public class Menu extends BasicGameState {
  
  private int stateID;
  private Image background;
  private UnicodeFont font;
  private TextField textfield;
  private Image createGameOption;
  private int menuX = 50;
  private int menuY = 250;
  
  
  public Menu(int stateID) {
      this.stateID = stateID;
  }
  
  
  @Override
  public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException {
  
      System.out.println("StateID: " + arg1.getState(this.getID()) + " , State: " + arg1.getCurrentState());
  
      background = new Image("images/background_1024x640_v1.jpg");
      createGameOption = new Image("images/btn_CreateGame_for_1024x640_v1.png");
  
      textfield = new TextField(arg0, arg0.getDefaultFont(), 100, 100, 200, 30);
  }
  
  
  @Override
  public void render(GameContainer arg0, StateBasedGame arg1, Graphics arg2) throws SlickException {
      // TODO Auto-generated method stub
      background.draw(0, 0);
      createGameOption.draw(menuX, menuY);
      textfield.render(arg0, arg2);
  
  }
  
  
  @Override
  public void update(GameContainer arg0, StateBasedGame arg1, int arg2) throws SlickException {
  
      Input input = arg0.getInput();
  
      int mouseX = input.getMouseX();
      int mouseY = input.getMouseY();
  
      // if mouse is over a button
      if ((mouseX &gt;= menuX &amp;&amp; mouseX &lt;= menuX + createGameOption.getWidth()) &amp;&amp; (mouseY &gt;= menuY &amp;&amp; mouseY &lt;= menuY + createGameOption.getHeight())) {
  
          if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
              // fx.play();
              arg1.enterState(ExampleGame.GAME_PLAY_STATE);
          }
  
      }
  
  }
  
  
  @Override
  public int getID() {
      // TODO Auto-generated method stub
      return stateID;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here I can write in the textfield. So far so good. By clicking on the button I call the next page (Play.java):</p>
  
  <pre><code>public class Play extends BasicGameState {
  
  private int stateID;
  private Image background;
  private UnicodeFont font;
  private TextField textfield;
  private Image createGameOption;
  private int menuX = 350;
  private int menuY = 250;
  
  
  public Play (int stateID) {
      this.stateID = stateID;
  }
  
  @Override
  public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException {
  
      System.out.println("StateID: " + arg1.getCurrentStateID() + " , State: " + arg1.getCurrentState());
      arg1.inputStarted();
  
      background = new Image("images/background_1024x640_v1.jpg");
      createGameOption = new Image("images/btn_CreateGame_for_1024x640_v1.png");
  
      textfield = new TextField(arg0, arg0.getDefaultFont(), 150, 100, 200, 30);
  }
  
  @Override
  public void render(GameContainer arg0, StateBasedGame arg1, Graphics arg2) throws SlickException {
      // TODO Auto-generated method stub
      background.draw(0,0);
      createGameOption.draw(menuX, menuY);
      textfield.render(arg0, arg2);
  }
  
  @Override
  public void update(GameContainer arg0, StateBasedGame arg1, int arg2) throws SlickException {
  
      Input input = arg0.getInput();
  
      int mouseX = input.getMouseX();
      int mouseY = input.getMouseY();
  
      if ((mouseX &gt;= menuX &amp;&amp; mouseX &lt;= menuX + createGameOption.getWidth()) 
              &amp;&amp; (mouseY &gt;= menuY &amp;&amp; mouseY &lt;= menuY + createGameOption.getHeight())) {
  
          if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
              arg1.enterState(ExampleGame.MAIN_MENU_STATE);
          }
      }
  }
  
  @Override
  public int getID() {
      // TODO Auto-generated method stub
      return stateID;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The class <code>Play</code> has almost the same code as <code>Menu</code> but it seems that the textfield in <code>Play</code> doesn't response to the mouse and key. It seems to be inactive because you can't see any changes. But that's actually not true. If I click in the textfield, type something and go back to the Menu by clicking the button, you can see the text you typed in. It seems that both textfields (the one from Menu and from <code>Play</code>) are connected to somehow. But I have no idea where the problem is from.</p>
  
  <p>Has anyone any suggestions how I can fix that?</p>
  
  <p>Thanks in advance! </p>