How to create own events in Java?

Posted on 1998-08-13
Medium Priority
Last Modified: 2008-02-01
How I can create my own events in Java? So that I can use them with HandleEvent?
Question by:Hugi
  • 3
  • 2

Expert Comment

ID: 1232584
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)


Author Comment

ID: 1232585
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.


Expert Comment

ID: 1232586
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.

Author Comment

ID: 1232587
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)


Accepted Solution

mjenkins earned 300 total points
ID: 1232588
hostname is "localhost" for the local machine. Always. You decide on a port number you would like to use. Any port number over 1000 is okay. Many people try ports in the 10000 - 11000 range.

So the call would be:

Socket connection = new Socket( "localhost", 10100 );

The server and client use the same port number.


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.
Suggested Courses

607 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