/**
 * file : JOldEvent1.java
 *
 * Demo Event handling using the Java 1.0 event model
 * Swing version
 * Note that the Swing controls do not participate in 
 * the queue based event model 
 * Swing controls are prefaced by J 
 * 	JButton, JLabel, JPanel
 * Old Style controls are simply: 
 * 	Button, Label, Panel
 * 
 * The methods action(Event, Object)
 *             handleEvent(Event)
 * are deprecated
 * 
 * Be careful - this is a strange mixture of old and 
 * new - your warranty is void befire you leave the showroom
 *
 * Use ^C  or kill -9 to quit
 */

 import java.awt.*;
 import javax.swing.*;

 public class JOldEvent1 extends JFrame {

 	private JButton b1;
	private JButton b2;
	private JButton b3;
	private Button awtButton;
	private JLabel label;
	private int eCount = 0;

 	JOldEvent1() {
		b1 = new JButton("Button 1");
		b2 = new JButton("Button 2");
		b3 = new JButton("Button 3");
		awtButton = new Button("awt");
		label = new JLabel("Nothing selected");

		//Use FlowLayout for this Frame
		getContentPane().setLayout(new FlowLayout());

		// add the buttons to the frame
		getContentPane().add(b1);
		getContentPane().add(b2);
		getContentPane().add(b3);
		getContentPane().add(awtButton);
		getContentPane().add(label);

		// show the frame
		setSize(300,200);
		setVisible(true);

	}//Constructor

 	/*
	 * called by the Java runtime
	 * Does NOT work with
	 * Swing components i.e. JButton
     	 */
	public boolean action(Event evt, Object arg) {
		if(evt.target.equals(b1)) {
			label.setText("Button 1 Pressed");
			System.out.println("Button 1");
		}
		else
			if(evt.target.equals(b2))
				label.setText("Button 2 Pressed");
			else
				if(arg.equals("Button 3"))
					label.setText("Button 3 Pressed");
				else
					if(evt.target.equals(awtButton)) {
						label.setText("awtButton");
						System.out.println("action method awtButton");
					}
					else
					// pass it up to java.awt.Component
					return super.action(evt,arg);

		// if the event was handled here
		// return true
		return true;

	}//action

	/*
	 * handleEvent does not work with Swing components
	 * Note the unusual behavior when
	 * the Swing components are mixed with the
	 * awt components
	 * When a swing button is clicked after the awt
	 * button is clicked, this method is called !!!!
	 */
	public boolean handleEvent(Event evt) {
		if(evt.target.equals(b1)) {
			label.setText("Button 1 Pressed");
			System.out.println("Button 1");
		}
		else
			if(evt.target.equals(awtButton)) {
				label.setText("awtButton");
				System.out.println("handleEvent method awtButton");
				System.out.println("eCount is :"+eCount++);
			}
			else
				return super.handleEvent(evt);

		return true;
	}//handleEvent

	public static void main(String[] args) {
		new JOldEvent1();
	}

 }//JOldEvent1
