import javax.swing.*; import java.awt.event.*; import java.awt.*; public class ButtonAppEvents extends JFrame { JButton b; JTextField t; MyActionListener al; public ButtonAppEvents(String name) { super(name); t = new JTextField(5); b = new JButton("Cuenta"); al = new MyActionListener(t); b.addActionListener(al); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(b); cp.add(t); } public static void main(String[] args) { JFrame frame = new ButtonAppEvents("Button Events"); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e){ System.exit(0); } }); frame.setSize(400,100); frame.setVisible(true); } } class MyActionListener implements ActionListener { int count; JTextField _t; public MyActionListener (JTextField t) { count=0; _t = t; } public void actionPerformed(ActionEvent e){ _t.setText(" "+count++); } }