[3081] in java-interest

home help back first fref pref prev next nref lref last post

Re: java menu events

daemon@ATHENA.MIT.EDU (Ron van Hoof)
Mon Oct 30 11:21:14 1995

Date: Mon, 30 Oct 1995 09:14:42 -0500
From: rvhoof@nynexst.com (Ron van Hoof)
To: jsanders@excelsior-73.Eng.Sun.C.sun.com
Cc: java-interest@java.sun.com

Hoi Jim, 

	It's very simple. You have to do the same thing as with
buttons. Just match the string text.

	if ("New".equals(arg)) {
		System.out.println("Creating new system!");
	}
	else if ("Open".equals(arg)) {
		System.out.println("Opening system!");
	}
	...

Ron

> 
> In a java application, how do you capture menu events?
> Below is an application with a menu bar and a couple
> of menus. There are also a couple of buttons
> in the app. The "action()" routine captures the events
> from buttons in the app, but not the menus.
> 
> Anybody have sample application code that deals
> with events from menubar menus?
> 	-Jim
> 
> 
> // create menubar with two menus
> 
> import java.awt.*;
> import java.applet.Applet;
> 
> public class menuBarTest extends Applet 
>   {
> 
>   public menuBarTest() 
>     {
>     setLayout(new BorderLayout());
>     Panel p = new Panel();
>     p.setLayout(new FlowLayout());
>     add("South", p);
>     p.add(new Button("quit"));
>     p.add(new Button("Doit"));
> 
>     }
> 
>   public boolean action(Event evt, Object arg) 
>     {
>     System.out.println("Event detected: " + arg); 
>     if ("quit".equals(arg))
>       {
>       System.exit(0);
>       }
>     if ("Doit".equals(arg))
>       {
>       }
>     return true;
>     }
>   public static void main(String args[]) 
>     {
>     Frame f = new Frame("menuBarTest");
>     menuBarTest menuBarTest_test = new menuBarTest();
>     menuBarTest_test.init();
>     menuBarTest_test.start();
> 
>     MenuBar mb = new MenuBar();
>     Menu h = new Menu("Help");
>     h.add("General Help");
>     h.add("Even More Help");
>     h.add("Extra Special Help");
>     mb.add(h);
>     mb.setHelpMenu(h);
> 
>     Menu h2 = new Menu("File");
>     h2.add("New");
>     h2.add("Open");
>     h2.add("Close");
>     h2.add("Save");
>     h2.add("Exit");
>     mb.add(h2);
>     f.setMenuBar(mb);
> 
> 
>     f.add("Center", menuBarTest_test);
>     f.resize(300, 300);
>     f.show();
>     }
>   }
> -
> This message was sent to the java-interest mailing list
> Info: send 'help' to java-interest-request@java.sun.com
> 


---------------------------------------------------------------------
Ron van Hoof                         NYNEX Science & Technology, Inc.
Member of Technical Staff            Research & Development
                                     Work Systems Design Group
E-Mail: rvhoof@nynexst.com	     400 Westchester Avenue, Rm 115a
Voice:  (914) 644-2046 		     White Plains, NY 10604
Fax:    (914) 949-9566 		     USA
---------------------------------------------------------------------
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post