// ActionListenerDemo.java // Basics of the ActionListener interface // Basics of GUI components import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ActionListenerDemo extends JApplet implements ActionListener { // GUI Components JLabel l; JTextField tIn, tOut; JButton b; public void init( ) { Container c = getContentPane( ); c.setLayout( new FlowLayout( ) ); l = new JLabel( "This is a label" ); c.add( l ); tIn = new JTextField( "This is a text field", 30 ); tIn.addActionListener( this ); c.add( tIn ); tOut = new JTextField( 30 ); tOut.setEditable( false ); c.add( tOut ); b = new JButton( "Button" ); b.addActionListener( this ); c.add( b ); } public void actionPerformed( ActionEvent e ) { if ( e.getSource( ) == tIn ) tOut.setText( "It was a text field event" ); else tOut.setText( "It was a button event" ); } }