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
Solved

handleEvent deprecated, use processEvent

Posted on 1998-12-18
17
1,351 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 58
check java version using powershell 13 172
runtime exception 2 41
Tagging and Merging on Branch 1 29
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…
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…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

856 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