Suppose you have many frames, you have to create instance variables for that purpose.
If you don't know what an instance variable see this tutorial.
Lets see an example:
This will be your frame that sends the variables :
public class MainFrame {
public void actionPerformed(ActionEvent ev) {
String user = userField.getText();
String pass = passField.getText();
FrameOne frameOne = new FrameOne();
frameOne.setUser(user);
frameOne.setPass(pass);
/*
* You've passed the user and pass to other frame,
* now you can make it visible.
*/
frameOne.setVisible(true);
}
And this will be your first frame:
public class FrameOne extends JFrame {
private JTextField userField;
private JTextField passField;
// then create setters and getter
public void setUser(String user) {this.userField.setText(user);}
public String getUser() {return this.userField.getText();}
public void setPass(String pass) {this.passField.setText(pass);}
public String getPass() {return this.passField.getText();}
public FrameOne() {
//define the components here
}
}
NOTE : I didn't compile the code, this is only for demonstration on your problem.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…