import java.awt.*; import javax.swing.*; public class Driver { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setLayout(new FlowLayout()); JTextField field = new JTextField("type stuff please", 20); field.setHorizontalAlignment(JTextField.CENTER); DoStuff ok = new DoStuff(field); frame.add(field); JButton button = new JButton("Submit"); frame.add(button); field.addActionListener(ok); button.addActionListener(ok); frame.pack(); } } import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JTextField; public class DoStuff implements ActionListener{ JTextField newField; int counter; public DoStuff (JTextField f) { newField = f; counter = 0; } public void actionPerformed (ActionEvent e) { if(e.getActionCommand() == "Submit") { System.out.println(newField.getText()); } else { newField.setText("NO HIT SUBMIT"); counter++; if(counter >= 3) { newField.setEditable(false); newField.setText("I told you so..."); } } } }