// Button3.java
// Introduction to anonymous inner classes

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Button3 extends JFrame {

  JButton b1 = new JButton("Button 1");
  JButton b2 = new JButton("Button 2");
  JTextField txt = new JTextField(10); 
  
  public Button3 () {
  	
  	// anonymous inner class
  	ActionListener al = new ActionListener () {
      public void actionPerformed(ActionEvent e){
         String name = 
           ((JButton)e.getSource()).getText();
         txt.setText(name);
       } 
    };

    b1.addActionListener(al);
    b2.addActionListener(al);
    b1.setBackground(Color.blue);
    b1.setForeground(Color.white);
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(b1);
    cp.add(b2);
    cp.add(txt);   
  }

  
  public static void main(String[] args) {
        JFrame frame = new Button3();
        frame.pack();
        frame.setVisible(true);
  }
} 



