package com.zindell.course.samples; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SimpleGUIEventsDemo implements ActionListener { private JButton btOne, btTwo, btThree; private JTextField tf; private JFrame frame; public SimpleGUIEventsDemo() { btOne = new JButton("One"); btTwo = new JButton("Two"); btThree = new JButton("Three"); tf = new JTextField(10); frame = new JFrame("Simple GUI Events Demo"); } public void go() { frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { System.exit(0); } }); btOne.addActionListener(this); btTwo.addActionListener(this); btThree.addActionListener(this); frame.setLayout(new FlowLayout()); frame.add(btOne); frame.add(btTwo); frame.add(btThree); frame.add(tf); frame.setSize(400,300); frame.setVisible(true); } public void actionPerformed(ActionEvent event) { Object src = event.getSource(); if(src==btOne) { tf.setText("1"); } else if(src==btTwo) { tf.setText("2"); } else if(src==btThree) { tf.setText("3"); } } public static void main(String args[]) { SimpleGUIEventsDemo demo = new SimpleGUIEventsDemo(); demo.go(); } }