[4675] in java-interest
Re: Problem with handling events (killing windows in a menubar of a frame & WINDOW_DESTROY)
daemon@ATHENA.MIT.EDU (Ben Evans - SolNet Technologies)
Wed Jan 10 16:43:24 1996
Date: Thu, 11 Jan 1996 09:17:22 +1300
From: bene@NewZealand.Sun.COM (Ben Evans - SolNet Technologies)
To: tan@cdr.stanford.edu
Cc: java-interest@java.Eng.Sun.COM
On Wed, 10 Jan 1996, Sian Tan <tan@cdr.stanford.edu> wrote:
>
> Hi.
>
> I'm trying to spruce up my user interface to have menuitem interaction.
> I'm using the method below to take care of mouse actions on the menubar
> of the frame. This works fine by itself. It kills the window. However,
> when I try to add the second code segment below into the same class, the
> window closes if I click the "close window" button on the window, but my
> menu items fail to function. What am I doing wrong here?
>
> And Sami Shaio, if and when you read this, my congratulations for
> producing a wonderful book. "Hooked on Java" really does the job.
>
> Reply by e-mail to: tan@cdr.stanford.edu is requested.
>
> *************** 1st code segment ***************
> public boolean action(Event evt, Object obj) {
> if (evt.target instanceof MenuItem) {
> String label = (String)obj;
> if (label.equals(QUIT)){
> this.dispose();
> System.exit(0);
> }
>
> etc. -------- etc.
>
> *************** 2nd code segment ***************
> public boolean handleEvent(Event evt) {
> switch(evt.id){
> case Event.WINDOW_DESTROY:{
> this.dispose();
> System.exit(0);
> return true;
> }
> default:
> return false;
> }
> }
> --
>
> **************************
> Sian Tan
> Center for Design Research
> 560 Panama Street
> Stanford, CA 94305
> Tel: 1-415-725 0161
> Fax: 1-415-725 8475
> **************************
> -
> This message was sent to the java-interest mailing list
> Info: send 'help' to java-interest-request@java.sun.com
Hi Sian,
I think the problem is that the default branch in your handleEvent()
does not call the action() method. Adding the following code should work...
*************** New 2nd code segment ***************
public boolean handleEvent(Event evt) {
switch(evt.id){
case Event.WINDOW_DESTROY:{
this.dispose();
System.exit(0);
return true;
}
default:
return action( evt, evt.arg ); <<--
}
}
You probably thought (as I did) that returning false from handleEvent()
would cause the AWT to call your overrided action() method. Apparently
this is not so! It looks like you have to manually call your own action()
method.
( Java gurus: am I right about this? Why doesn't AWT automatically call
the action() method? )
Hope this helps.
/************************
* Ben Evans
* Systems Engineer
* SolNet Technologies Ltd
* PO Box 397
* Wellington, New Zealand
* Ph: +64-4-4720688
* Fax: +64-4-4720669
*************************/
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com