Solved

handleEvent deprecated, use processEvent

Posted on 1998-12-18
17
1,335 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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 first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

746 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

16 Experts available now in Live!

Get 1:1 Help Now