Solved

Event Driven in Java???

Posted on 1997-11-24
5
440 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
strCopies  challenge 17 73
topping2 challenge 13 59
Free Alternative to JIRA 4 55
JAVA part two 5 41
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

705 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

21 Experts available now in Live!

Get 1:1 Help Now