Hi everyone,

I am a C/C++ winapi developer and have to rewrite a "Dialog based" application in java, so that it will execute as an applet in any browser.

My java skills are very few, since my knowledge is limited to past college classes.

The application is not a large scale one, since it only implements a GUI, with a few screen interactions, which are driven by data from udp network connections.

In a windows development model, i would create worker threads wich handle the network communication and feed the gui with data through the window message queue, probably using SendMessage or PostMessage functions.

So my question is, how do i implement this kind of model in java?
I am not interested, for the time being, in learning another model of thread communication, i just want to know if there is anyway to apply the same model in java, because i am quite familiar with it.

Thanks in advance!

Recommended Answers

All 6 Replies

you're going to have to learn Java if you're going to use it, there's no way around it.
Trying to push an entirely different development model into the language isn't going to get you very far.
With your attitude you're setting yourself up for a very rapid failure.

Follow some Swing and applet tutorials, and you'll see instantly that what you're trying to do isn't going to work.

Thanks for the insight.
I am not trying to apply the exact same model. All i want is a suggestion on which thread communication model is closer to the one i described. I am going to learn java eventually, but i just need to implement something based on a model i allready know.
For instance this article only suggests 8 different thread communication approaches.
http://bighai.com/ppjava/?p=140
So all i need is someone who has experience in both languages to tell me which way is going to be easier for me to understand and implement.

I know it's wrong but i don't have the time to read entire books and get in depth knowledge of java.
I find it more helpful to try developing something and getting to know each concept on its own.

Thanks.

You could push your messages onto a LinkedBlockingQueue from one thread, and loop processing them in another (take from the queue blocks if the queue is empty)
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedBlockingQueue.html
(but I agree with jwenting)

ps: Looking at the 8 ways in your link, it's number 4 ("Observable") that The Java GUI API uses for cases like this.

Thanks James, i've read about the BlockingQueue, and it seems like a nice and clean solution for message passing, but it is not event driven and it leaves the implementation of the dispatching to you.

This seems like a more transparent way to implement it :
http://www.javaworld.com/javatips/jw-javatip10.html
Do you have any experience on this subject?
Would you suggest it?

Thanks again.

Yes yes! YES. That's exactly the "Observable" pattern that I recommended earlier. It's how the Java API handles re-painting windows when required, responding to keystrokes or mouse events, everything. Java maintains its own event queue, but it dispatches the events by calling registered "listeners" ("callbacks") for each type of event. It's a way that any experienced Java programmer would do this.

You define an interface (one or mode method signatures) for passing network events. Your GUI implements that interface, and registers itself as a listener on thr network handler. When a network event happens, the network handler calls all the registered listeners, passing the relevant data.

Being familiar with callbacks, it was easier for me to understand it that way!
Java's abstraction is really great, but it takes sometime to get used to it i suppose, specially if you are used to old-school winapi development!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.