import java.awt.*;
import java.awt.event.*;

public class MenuTest extends Frame {

Menu m,n,optionsMenu;
MenuItem q,r,t,u;
CheckboxMenuItem s;
MenuBar mb;

public MenuTest() {
	super("MenuTest"); 		
               // set the title of the frame
	m = new Menu ("Examples");
	optionsMenu = new Menu ("Options");

	m.add(q= new MenuItem("Basic"));
	m.add(r=  new MenuItem("Simple"));

	// add a separator
	m.add(new MenuItem("-"));

	// add a Checkbox item 
	m.add(s= new CheckboxMenuItem("Check"));

	// add a submenu 
	n = new Menu("More Examples");
	n.add(t= new MenuItem("Sub Basic"));
	n.add(u= new MenuItem("Sub Simple"));
	m.add(n);

	q.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e){
                              System.out.println ("this is :" + 
((MenuItem)e.getSource()).getLabel()) ; }});   				
            // or do cool things	

	r.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e){
                              System.out.println ("this is:" + 
((MenuItem)e.getSource()).getLabel()) ; }});   				
            // or do cool things

	s.addItemListener(new ItemListener() {
               public void itemStateChanged(ItemEvent e){
		  boolean label = ((CheckboxMenuItem)e.getSource()).getState();
			System.out.println ("The new checkbox state is " + label); 
		    						      }});
	t.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e){
                              System.out.println ("this is :" + 
((MenuItem)e.getSource()).getLabel())  ; }});   				
							// or do cool things
	u.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e){
                              System.out.println ("this is:" + 
((MenuItem)e.getSource()).getLabel()) ; }});   			
							// or do cool things
	
	mb = new MenuBar();
	mb.add(m);
	mb.add(optionsMenu);
	setMenuBar(mb); 
}

public void start() {
	setSize(300, 300);
	setVisible(true);
  }

  public static void main(String args[]) {
	MenuTest m = new MenuTest();
	m.start();
  } 
}

