There are two players who will input their name in the JTextFields. What I want to do is that the data I entered from the Welcome frame in Enter.java will be transferred to the
Try to make ActualGam as a underclass of Enter
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
public class Enter extends JFrame implements ActionListener {
private String one = "";
private JTextField txtOne = new JTextField();
public Enter() {
this.setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Welcome");
setSize(200, 130);
setVisible(true);
setResizable(false);
setLocationRelativeTo(null);
add(txtOne);
enter.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
Main main = new Main();
this.setVisible(false);
one = txtOne.getText();
}
class ActualGame extends JPanel{
private JLabel lblOne = new JLabel(one);
public ActualGame() {
setLayout(new FlowLayout());
Enter.this.add(lblOne);
}
}
}