?
Solved

handleEvent deprecated, use processEvent

Posted on 1998-12-18
17
Medium Priority
?
1,389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 150 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 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