What I would do is create instance variables for a JButton and JTextField in your main application GUI class. Then, add your application as the ActionListener for the JButton. Everytime the JButton is clicked, it will send an ActionEvent to your actionPerformed method (you must implement this method
public class GUI implements ActionListener
{
// a simple class that implements an ActionListener
public void actionPerformed(ActionEvent e)
{
// any code you want whenever this method is triggered
if (e.getAction.equals("Add"))
{
// received an action labeled "Add". Stuff to handle this action is here
}
}
}
By default, JButton sends out the action that matches it's displaying text, but this can be changed using the setActionCommand(String action) method. To add your program as an action listener to a JButton (or most other swing components):
someJButton.add(someActionListener);
Practically, this should be somewhere inside of your GUI initializer method, so it can look something like this:
Because you don't need to keep track of the text everytime it changes and only when the button is pressed, you can poll the text only when the action event is fired. To get the text in the JTextField:
someJTextField.getText();
hopefully that helps you with the swing portion of your program.