Solved

Event Driven in Java???

Posted on 1997-11-24
5
443 Views
Last Modified: 2012-06-21
Hi, there:
      It seems like Java has delegation Model for AWT event.  Do you know if this model is fit for any event?  I want to write an event-driven application in Java in which not only is driven by AWT event but also driven by any event like when some data higher than a threshhold, etc. Is that possible to use that model?  If so, how to use it?  Thanks a lot.

Gang Feng
0
Comment
Question by:feng042497
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1231144
Using Introspection you can certanly create your own listeners and events and associate them to given threshholds.

Could you be a bit more clear about what kind of events you wish to monitor?

Most OS events (like timers, interrupts, etc) will have to be handled by native methods via JNI. On the other hand, you can handle most data and AWT "action" events via introspection and other techniques.

With a better idea of exactly what you wish to watch for we could give you a better answer.
0
 
LVL 1

Accepted Solution

by:
fadl earned 50 total points
ID: 1231145
The answer is Yes.
You can do both. Create your own events extending standard
AWT events and then to use them.
      (I wrote TextArea replacement and I have two
      more events such as CaretMovedEvent etc and
      my own TextAWTMutlicaster - it is then used
      via add/removeXXXListener as usually)
You can create your own events/listeners interfaces and
a kind of dispatching mechanism too. (See sources to
AWT events and AWTMulticaster as a starting point -
it's not so difficult as it might seem to)

If this is not enough, please be more specific about nature
of your task.
HTH
Michal
fadl@corpus.cz


0
 

Author Comment

by:feng042497
ID: 1231146
Hi, fadl:
      Thank you for answering this question!  I got some idea from your explaination.  But I didn't totally understand.  What kind of dispatching mechanism are you using in your program?  From the book, dispatchEvent(AWTEvent e) seems like only can dispatch event to its subcomponent.  Do you mind showing me your program?  Thanks a lot.

Gang Feng
0
 
LVL 1

Expert Comment

by:fadl
ID: 1231147
I needed to create a couple of new events in my Text
component (TextArea replacement) e.g. CaretMovedEvent
etc
To handle those new events one must implement dispatching
algorithm such as the one in AWTMulticaster class (in AWT)
I wrote my own TextAWTMutlicaster object that handles
my new events.
Generally it is not necessary to do things like this.
You can e.g. store your listeners in Vector {:) - it
works too.

Send me your e-mail address and I will send you
zipped sources to see it in action. You will understand
soon how to do it.

Michal
fadl@corpus.cz
0
 

Author Comment

by:feng042497
ID: 1231148
Hi, Michal:
      Have you received the mail I sent you?  I haven't received the reply?  So I think maybe you didn't get it.  My email address is g0f4653@cs.tamu.edu.  Have a good one!

Gang Feng
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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

911 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

15 Experts available now in Live!

Get 1:1 Help Now