Jump to content
  • Advertisement
Sign in to follow this  
lifesuxtr

How to add button and textbox to LoginState

This topic is 549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!