So here I have two classes: Customer Order Class and Confirmation Class. I want to access the data stored in LastNameTextField (Customer Order Class) and set it as the text for UserLastNameLabel (Confirmation Class) after clicking a "Submit" button. For some reason however, the output displays nothing.
Snippet of my code:
package customer_order;
public class customer_order extends Frame{
private static final long serialVersionUID = 1L;
private JPanel jPanel = null;
private JLabel LastNameLabel = null;
protected JTextField LastNameTextField = null;
private JButton SubmitButton = null;
public String s;
public customer_order() {
super();
initialize();
}
private void initialize() {
this.setSize(729, 400);
this.setTitle("Customer Order");
this.add(getJPanel(), BorderLayout.CENTER);
}
/**
* This method initializes LastNameTextField
*
* @return javax.swing.JTextField
*/
public JTextField getLastNameTextField() {
if (LastNameTextField == null) {
LastNameTextField = new JTextField();
LastNameTextField.setBounds(new Rectangle(120, 100, 164, 28));
LastNameTextField.setName("LastNameTextField");
}
return LastNameTextField;
}
/**
* This method initializes SubmitButton
*
* @return javax.swing.JButton
*/
private JButton getSubmitButton() {
if (SubmitButton == null) {
SubmitButton = new JButton();
SubmitButton.setBounds(new Rectangle(501, 225, 96, 29));
SubmitButton.setName("SubmitButton");
SubmitButton.setText("Submit");
SubmitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
//THE STRING I WANT
s = LastNameTextField.getText();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new confirmation().setVisible(true);
}
});
}
});
}
return SubmitButton;
}
package customer_order;
public class confirmation extends customer_order{
private static final long serialVersionUID = 1L;
private JPanel jPanel = null; // @jve:decl-index=0:visual-constraint="58,9"
private JLabel LastNameLabel = null;
private JLabel UserLastNameLabel = null;
// @jve:decl-index=0:
/**
* This method initializes frame
*
* @return java.awt.Frame
*/
public confirmation() {
super();
initialize();
}
private void initialize() {
this.setSize(729, 400);
this.setTitle("Confirmation");
this.add(getJPanel(), BorderLayout.CENTER);
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
UserLastNameLabel = new JLabel();
UserLastNameLabel.setBounds(new Rectangle(121, 60, 167, 26));
//THE PROBLEM?
UserLastNameLabel.setText(s);
}
return jPanel;
}