How to send Data From One JFrame To Another in Swing?
We can Create Object and pass the value as a parameter from First Frame to another.
Frame2 obj = new Frame2(data);
obj.setVisible(true)
and in Frame2() create parametrized Constructor and get the parameter value and assign it into Label or Output Variable.
1) CREATE DESIGN
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(jTextField1.getText().toString().equals("admin") && jPasswordField1.getText().toString().equals("12345"))
{
new Dashboard(jTextField1.getText().toString()).setVisible(true);
}
else
{
JOptionPane.showMessageDialog(null, "Invalid Userid and password");
}
}
2) CREATE DESIGN2 AND CODE
public Dashboard(String s) {
initComponents();
jLabel2.setText(s);
}
Post a Comment
POST Answer of Questions and ASK to Doubt