[1989] in java-interest

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

Re: AWT Menu Events

daemon@ATHENA.MIT.EDU (Sami Shaio)
Thu Sep 21 00:00:33 1995

Date: Wed, 20 Sep 1995 16:30:44 -0700
From: Sami.Shaio@Eng.Sun.COM (Sami Shaio)
To: java-interest@java.Eng.Sun.COM, NickR@silverplatter.com
Cc: Sami.Shaio@Eng.Sun.COM


|From NickR@silverplatter.com Wed Sep 20 16:03:44 1995

|     My current questions is how do I get notified when a menu item is 
|     selected. Looking at the HotJava alpha 3 source it uses the selected 
|     method of the menu class but the prebeta awt does have such a method, 
|     what do I use instead ?
|     

See attached program below.

|     On a more general note, learning the awt would be eased if an overview 
|     document describing its overall structure, event handling mechanism 
|     etc was available, is such a beast on the way ? A sample program that 
|     used the prebeta awt to create a app would also be useful.
|     

Yes, better docs are on the way including an overview and tutorial for
awt. We just wanted to put this stuff out to get feedback before the
docs were ready since good docs take time to write.

|     Are there any plans to add the ability to store text strings, menus 
|     etc in a seperate resource file to java ? This is needed to ease 
|     internationalisation of java applications.
|     

There is a property method, System.getProperty that will get used for
this purpose. It still needs some fleshing out but that is its intent.

|     many thanks,
|     
|     Nick Roberts
|     


Here's a simple awt program that puts up a menubar and prints out the
contents of a menu item when selected. Compile it with javac and then
just run it as "java MenuTest":

import java.awt.*;

public class MenuTest extends Frame {
  public MenuTest() {
	super("MenuTest"); // set the title of the frame
	MenuBar mb = new MenuBar();

	// add a simple menu
	Menu m = new Menu("Numbers");
	m.add(new MenuItem("one"));
	m.add(new MenuItem("two"));
	m.add(new MenuItem("three"));

	// add a submenu
	Menu submenu = new Menu("More Numbers");
	submenu.add(new MenuItem("four"));
	submenu.add(new MenuItem("five"));
	m.add(submenu);
	
	setMenuBar(mb); // install this menu bar in the frame

	resize(300, 300);
	show();
  }
  public boolean handleEvent(Event evt) {

	if ((evt.id == Event.ACTION_EVENT) && (evt.target instanceof MenuItem)){
		System.out.println(evt.target.getLabel());
	}
  }
  public static void main(String args[]) {
	new MenuTest();
  }
}


|     *******************************************************************
|
|     SilverPlatter Information Ltd      Phone : +44-(0)181-995-8242
|     10 Barley Mow Passage              Fax   : +44-(0)181-995-5159
|     Chiswick                   Email : nickr@silverplatter.com
|     London W4 4PH                      Compuserve : 100014,2166
|     United Kingdom
|     
|     *******************************************************************
|     
|     
|
|-
|Note to Sun employees: this is an EXTERNAL mailing list!
|Info: send 'help' to java-interest-request@java.sun.com
|
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

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