Solved

How to create own events in Java?

Posted on 1998-08-13
5
178 Views
Last Modified: 2008-02-01
How I can create my own events in Java? So that I can use them with HandleEvent?
0
Comment
Question by:Hugi
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:mjenkins
Comment Utility
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)


0
 

Author Comment

by:Hugi
Comment Utility
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.

0
 
LVL 3

Expert Comment

by:mjenkins
Comment Utility
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.
0
 

Author Comment

by:Hugi
Comment Utility
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)


0
 
LVL 3

Accepted Solution

by:
mjenkins earned 100 total points
Comment Utility
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.

OK?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 54
scoresSpecial  challenge 13 40
basic hardware to learn oop advanced design patterns 3 71
word0 challenge 3 55
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 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

11 Experts available now in Live!

Get 1:1 Help Now