/**
 * file: ActionCommand.java
 *
 * Demonstrate the use of the getActionCommand()
 * method of class java.awt.event.ActionCommand
 *
 */

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

public class ActionCommand extends JFrame implements ActionListener {

    	public ActionCommand() {

		// invoke the super class Constructor
		super("A Basic Frame");

		// an anonymous inner class ro handle the window close
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {System.exit(0);}
        	});

		// create a swing label
        	JLabel label = new JLabel("Something to look at",JLabel.CENTER);

		label.setVerticalTextPosition(JLabel.TOP);
		label.setHorizontalTextPosition(JLabel.CENTER);

		// create some swing buttons
		// these will be the action commands
		JButton jb = new JButton("Go");
		JButton jb2 = new JButton("Stop");

		// both buttons share the same listener
		jb.addActionListener(this);
		jb2.addActionListener(this);

		//add them to the content pane (like realizing the widgets in X)
		getContentPane().add(jb, BorderLayout.NORTH);
		getContentPane().add(label, BorderLayout.CENTER);
		getContentPane().add(jb2, BorderLayout.SOUTH);

 		// make the frame visible
		setSize(300,300);
		setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		String s = e.getActionCommand();
		System.out.println("Action Command:"+s);
	}

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

}//ActionCommand
