Solved

handleEvent deprecated, use processEvent

Posted on 1998-12-18
17
1,343 Views
Last Modified: 2007-12-19
my old code was:

  public boolean handleEvent (Event evt)  {
    // allow for new values being entered input field
    if (evt.id == Event.WINDOW_DESTROY) {
      // any closing stuff goes here
      System.exit(0);
      return true;
    }
  }

but handleEvent has been deprecated and i must use processEvent
something like:

  public boolean processEvent(AWTEvent evt)  {
    // allow for new values being entered input field
    if (evt.id == AWTEvent.???) {
      // any closing stuff goes here
      System.exit(0);
      return true;
    }
  }

but there isn't a parallel between events in Event and AWTEvent
what needs to be done?
0
Comment
Question by:jdaues
  • 7
  • 4
  • 3
  • +2
17 Comments
 
LVL 1

Expert Comment

by:mrgentry
ID: 1229717
How about java.awt.event.WindowEvent.WINDOW_CLOSED.  This event will be triggered after a call to dispose().

0
 

Author Comment

by:jdaues
ID: 1229718
there is something differnt about the mechanism, because if i do:

    if (event.id == java.awt.event.WindowEvent.WINDOW_CLOSED)

i get the compile rror:

Error: Variable id in java.awt.AWTEvent not accessible

0
 

Author Comment

by:jdaues
ID: 1229719
i should, that i see "id" in the AWTEvent class description,
so i'm not sure what it is thats different

0
 

Author Comment

by:jdaues
ID: 1229720
one difference is that it is public in Event and protected in AWTEvent

0
 
LVL 1

Expert Comment

by:mrgentry
ID: 1229721
I have to correct my answer. :)  You need to have register a WindowListener and do whatever you need to do when the window closes in the windowClosed method (which takes a WindowEvent not an AWTEvent).
0
 

Author Comment

by:jdaues
ID: 1229722
how do you register a WindowListener
i've never done that

0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229723
this is the simplest examle - using inner class. you can read about Java1.1 event handling and innner classes in the docs (even in your JDK.1.1 documentation ...)

import java.awt.*;
import java.awt.event.*;

public class test {
    public static void main(String s[])
    {
        Frame frame = new Frame("Demo");
        frame.addWindowListener(new WindowAdapter()
            {
              public void windowClosing(WindowEvent e) {System.exit(0);}
            });

        frame.add(new Button("button));
        frame.pack();
        frame.setVisible(true);
    }
}


0
 

Author Comment

by:jdaues
ID: 1229724
sorry for the delay...this one is on hold for a bit
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:nbell
ID: 1229725
I would like to add that there is another way to do what heyhey did. He used an anonymous class to listen for a specific WindowEvent. I would like to show the "low-level" way of handling the same event:


import java.awt.*;
import java.awt.event.*;

public class Test extends frame{
    public static void main(String s[])
    {
        new Test();
    }

    public Test(){
        super("TestFrame");
        this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        this.add(new Button("button"));
        this.setVisible(true);
    }

    public void processWindowEvent(WindowEvent e){
         if (e.getID()==WindowEvent.WINDOW_CLOSING)
               System.exit(0);
         else super.processWindowEvent(e); //it is a good idea to
//pass unhandled events to superclass, but not necessary
}
}
0
 

Author Comment

by:jdaues
ID: 1229726
mrgentry, please unlock this question
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229727
jdaues:

you must reject the answer to unlock the question.

0
 

Author Comment

by:jdaues
ID: 1229728
heyhey, please lock.
the code i am using looks most like your suggestion.

0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 50 total points
ID: 1229729
thanks
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 4998307
Hi,

I am very new to java,
and i had the same problem as follows:

postEvent(new Event(this, 1994, null))
handleEvent(new Event(this, 1994, null))

all are deprecated and needs to be changed to

dispatchEvent(EWTEvent) and
processEvent(EWTEvent)

as you see the type of the argument changed

How can I change them,
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 5027700
helloooo
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 5031899
this question is already locked. you are supposed to post NEW QUESTION.

P.S. hint: read some tutorial about the 'new' 1.1 EventArchitecture :)
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 5045999
i did

i intended to give points to who answers me, but since this question have an expert connected, i tried to notify him/her by the new question, thats it,

any how the question is in the Java area.Q_11724518

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 43
netstat -ano | find "8000" and taskkill /f /pid 2984 3 38
replace a word with other 1 40
xampp tool 12 28
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now