Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Event Driven in Java???

Posted on 1997-11-24
5
Medium Priority
?
464 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

824 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