I have two class, one is for swing and main class, one is for actionperformed method
//class swing
package system;
import javax.swing.*;
import java.awt.event.*;
public class GUI{
JFrame frame = new JFRame("frame");
JTextField tx = new JTextField(10);
JButton bt = new JButton("button");
public void getTx(){
return tx.getText();
}
public void init(){
frame.setSize(200, 200);
frame.add(tx);
frame.add(bt);
tx.setBounds(20, 20, 140, 50);
bt.setBounds(20, 100, 120, 40);
btaddcom.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
control.btclicked(e);
}
});
}
public GUI(){
init();
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable(){
public void run() {
new GUI().frame.setVisible(true);
}
});
}
}
below is my other class
package system;
import java.awt;
import java.awt.event.*;
public abstract control implements ActionListener{
public static void btclicked(ActionEvent e){
GUI gui = new GUI();
String txf = gui.getTx();
JOptionPane.showMessageDialog(null, txf);
}
}
My question is why I cannot get the value from JTextField tx, because it is always blank whenever text I filled it. Thanks