Sign in to follow this  
lifesuxtr

How to add button and textbox to LoginState

Recommended Posts

Hi guys working on a login system on a 2d rpg game.

Basically we have a state manager,menu state,login state etc...


im trying to add JButton and JTextbox to one of this states but i couldnt do that.

First this is display class

import java.awt.Canvas;


import java.awt.Dimension;

import javax.swing.JFrame;

public class Display {

   private JFrame frame;
   private Canvas canvas;
   
   private String title;
   private int width,height;
   
   public Display(String title,int width,int height){
      this.title = title;
      this.width=width;
      this.height=height;
      createDisplay();
     
   }
   private void createDisplay(){
      frame = new JFrame(title);
      frame.setSize(width, height);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setResizable(false);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
      canvas = new Canvas();//initilize.
      canvas.setPreferredSize(new Dimension(width,height));
      canvas.setMaximumSize(new Dimension(width,height));
      canvas.setMinimumSize(new Dimension(width,height));
      canvas.setFocusable(false);///!!! key calissin diyee.focusla ilgili.
      frame.add(canvas);
      frame.pack();

   }
   public Canvas getCanvas(){ //getter
      return canvas;
   }
   public JFrame getFrame(){
      return frame;
   }
   
   
}

This is the login state.I want to add Jbutton and textbox to this state.

import java.awt.Graphics;

public class LoginState extends State {
   private UIManager uiManager;

   public LoginState(final Handler handler) {
      super(handler);
      uiManager = new UIManager(handler);

      uiManager.addObject(new UIImageButton(200, 200, 400, 64, Assets.btn_start, new ClickListener() { 
         @Override
         public void onClick() {
            handler.getMouseManager().setUIManager(uiManager);
            State.setState(handler.getGame().gameState);
         }
      }));

   }

   
   public void tick() {
      uiManager.tick();
      handler.getMouseManager().setUIManager(uiManager);
      State.setState(handler.getGame().LoginState);
     
   }

   @Override
   public void render(Graphics g) {
      uiManager.render(g);
   }
   
}

I can add UIImage button which is just a buttonclass with a picture etc butI want to add JButton and Jtextbox to the state for a login register system.i tryed

display.getcanvas.add(button)
like that but its not working and actually i wonder how people add JButton or Jtextfields to their game states ?

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this