Link to home
Start Free TrialLog in
Avatar of Hugi
Hugi

asked on

How to create own events in Java?

How I can create my own events in Java? So that I can use them with HandleEvent?
Avatar of mjenkins
mjenkins
Flag of United States of America image

If you really mean to handle the events using Component.handleEvent you just need to subclass the java.awt.Event class. Then call postEvent( event ) for the target component. This only applies to JDK 1.0.2, however.

If you want to use JDK 1.1+ then you need to subclass java.awt.AWTEvent and call Toolkit.getEventQueue().postEvent(event)


Avatar of Hugi
Hugi

ASKER

I don't know if you did understood my question...
What I want to do is, to start an application and send an event which I can receive by another application.

Do you mean in two separate JVM's? That would mean some sort of IPC (inter-process communication). The best thing to do would be to open a socket between the two processes and pass your events as serialized objects.
Avatar of Hugi

ASKER

And how can I do that?
I have found the following, but I want to communicate between two Processes on the same machine:
Socket connection = new Socket(hostname, portnum)


ASKER CERTIFIED SOLUTION
Avatar of mjenkins
mjenkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial