Solved

handleEvent deprecated, use processEvent

Posted on 1998-12-18
17
1,348 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

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
 

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ForLoop Example 3 49
diffSum example 4 37
nextBoolean(double p) for Random class 3 40
map related example 6 49
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

809 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