/* MultipleEvents3.java * * This program illustrates one way to handle multiple events in a single program - by * having a different listener for each event source.  The listeners are instances of * an inner class named ColorChangeListener.  Each instance is told what color to * change to when it is constructed, and stores this value for use by the * actionPerformed() method. The GUI consists of a window that can be drawn in one of * three colors, and three buttons that can be used to change the color * * Copyright (c) 2000, 2004 - Russell C. Bjork */ import java.awt.*;import java.awt.event.*;import javax.swing.*;public class MultipleEvents3 extends JFrame{	// Constructor - create the GUI		public MultipleEvents3()    {         super("MultipleEvents Demo #3");      	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		// Add the buttons - in their own panel        JPanel buttonPanel = new JPanel();        JButton redButton = new JButton("Red");        redButton.addActionListener(new colorChangeListener(Color.red));        buttonPanel.add(redButton);        JButton greenButton = new JButton("Green");        greenButton.addActionListener(new colorChangeListener(Color.green));        buttonPanel.add(greenButton);        JButton blueButton = new JButton("Blue");        blueButton.addActionListener(new colorChangeListener(Color.blue));        buttonPanel.add(blueButton);        getContentPane().add(buttonPanel, BorderLayout.SOUTH);                setSize(300, 200);    }        // Objects of this inner class serve as the event listeners        private class colorChangeListener implements ActionListener    {      	colorChangeListener(Color changeTo)      	{      	    this.changeTo = changeTo;      	}	    public void actionPerformed(ActionEvent event)	    { 	      	getContentPane().setBackground(changeTo);	      	repaint();	    }	    private Color changeTo;	}        // Main program - Create the GUI and let it do the work     public static void main(String [] args)    {    	new MultipleEvents3().setVisible(true);   	}}