[4223] in java-interest

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

Re: Menubars

daemon@ATHENA.MIT.EDU (Patrick Taylor)
Wed Dec 13 19:26:10 1995

Date: Wed, 13 Dec 1995 17:33:38 -0500
From: Patrick Taylor <patrick.taylor@template.com>
To: java-interest@java.sun.com


   From: robertf@sshare.com (Robert Fox)
   Date: Tue, 12 Dec 95 10:01:44 PST
   Subject: Menubars

   I am using Netscape to view my applets... I have created a Frame and attached
   a MenuBar to it... Netscape spawns a window with a frame, but I cannot
   close the frame (using the system menu->Exit or hitting the 'X' in upper
   right doesn't work!). The only way I have found to destroy the frame is
   by closing Netscape! Does anyone know how to get around this? Or is this
   simply a bug in Netscape...

For some reason which I do not know, the Frame class does not handle the
WINDOW_DESTROY Event.  It ignores it.  You must subclass Frame and redefine
the handleEvent method to call dispose() on a WINDOW_DESTROY Event.
Typically, you need to subclass anyway because you'll want to define the
handling of other events in the frame, such as button presses and menu
selections.  For example:

   public boolean handleEvent(Event evt) {
       switch (evt.id) {
	 case Event.ACTION_EVENT:
	    String s = evt.arg.toString();
	    if (s.equals("Pack")) {
	       this.pack();
	    } else if (s.equals("Close")) {
	       this.dispose();
	    } else if (s.equals("Exit")) {
	       System.exit(0);
	    }
	    return true;
	 case Event.WINDOW_DESTROY:
	    this.dispose();
	    return true;
       }
       return super.handleEvent( evt);
   }
-
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