Pass values entered in one JFrame's text field as an input parameter in other JFrame

前端 未结 4 593
执念已碎
执念已碎 2020-12-17 07:42

How to pass values entered in one JFrame\'s text field as an input parameter in other JFrame?

Entered user name and password in first JFrame through

4条回答
  •  伪装坚强ぢ
    2020-12-17 08:13

    You can also pass values to the constructor like this

    Your main frame

    public class MainFrame{
          //
          public void actionPerformed(ActionEvent ev){
    
           FrameOne frameOne = new FrameOne(userField.getText(), passField.getText());
    
           //you've passed the user and pass to other frame.
           // then you can make it visible.
           frameOne.setVisible(true);
         } 
    } 
    

    Your next frame

    public class FrameOne extends JFrame{
      private String user;
      private String pass;
    
      public FrameOne(String usr, String pas){
        this.user=usr;
        this.pass=pas;
        //define the components here
     }
    }
    

提交回复
热议问题