[2872] in java-interest

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

Re: timed read

daemon@ATHENA.MIT.EDU (Ron van Hoof)
Wed Oct 18 21:58:14 1995

Date: Wed, 18 Oct 1995 19:56:24 -0400
From: rvhoof@nynexst.com (Ron van Hoof)
To: neudeck.arthur@ch.swissbank.com
Cc: java-interest@java.sun.com

Hi Arthur!

	below a simple example of how to create a menu bar and how
to handle it's events.

Hope this helps.

Ron

----------
Pre-beta-code

class MenuForm extends Frame {

	// Attributes
	//		Constants
	int formWidth = 240;
	int formHeight = 300;
	//		Variables
	MenuBar mbar;			// menubar, just for testing

	// Methods
	public MenuForm() {
		// set the title of the form by calling the parent's constructor
		super("Menu Form");

		initializeMenus();
		setMenuBar(mbar);

		resize(formWidth,formHeight);

		show();
	} //MenuForm

	public boolean action(Event evt, Object arg) {
		// Handling the menu-items
		if ("Quit".equals(arg)) {
			this.dispose();
		}
		else if ("Open".equals(arg)) {
			System.out.println("Opening something...");
		} 
		else if ("Save".equals(arg)) {
			System.out.println("Saving something...");
		} 
		else if ("Save As...".equals(arg)) {
			System.out.println("Saving something as ...");
		} 
		else if ("About".equals(arg)) {
			System.out.println("Ok, ok, that's not "+
				"present yet...");
		} 
		else {
			return false;
		}
		return true;
	} // action

	private void initializeMenus() {
		mbar = new MenuBar();
		Menu fileMn = new Menu("File");
		fileMn.add(new MenuItem("New"));
		fileMn.add(new MenuItem("Open..."));
		fileMn.add(new MenuItem("Save"));
		fileMn.add(new MenuItem("Save As..."));
		fileMn.addSeparator();
		fileMn.add(new MenuItem("Quit"));
		mbar.add(fileMn);

		Menu helpMn = new Menu("Help");
		helpMn.add(new MenuItem("About"));
		mbar.add(helpMn);

		// Sets the help menu on the right side in the menu-bar
		mbar.setHelpMenu(helpMn);
	} // initializeMenus

} // MenuForm



---------------------------------------------------------------------
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
---------------------------------------------------------------------
-
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