Skip to main content
gamedev.net
🔒 Locked

Java Program Flow

Started by dave Jan 27, 2006 at 3:14 PM 4 replies 850+ views
Original Post
dave
dave
Hey everyone, I'm wondering if anyone can give me a quick couple of lines explaining how the program flows when you are using Java Swing for the GUI. It's pretty obvious when you are doing a console app. I am asking this because i want to write a server with a GUI and ofcourse the server needs to probe the ports as well as hand on the GUI messaging. However, if you have to use a Timer class to poll, i know how to do it. Can anyone enlighten me? Thanks, Dave
Metaphorically
Metaphorically
Maybe the Sun tutorials on EventListeners might help you out.

The difference between a console app and most GUIs is that in a console, you write the main line and call things in your order. With a GUI framework you have a situation called Inversion of Control. You set up event listeners and the framework calls the event code when appropriate.

hth
Dragoncar
Dragoncar
In the gui application, when your programming isn't handling an event already it will be sitting waiting for events (ie. mouse click, key press etc.) and then when it gets one of these events it will call the appropriate method for that type of event in which you can you can determine what was done and take the appropriate action.

So basically instead of just travelling through your code, the gui will wait for an event and then goto the method for determining what to do and then to the method you tell it too for the particular button, checkbox etc.

So yes, you could use a timer and then check the port/s when you get a timer event. However you could also look into using threads and have one thread handling the gui and the other handling the port/s and data coming in off them and as much as possible the data manipulation.

By the way what do you need a gui running constantly on the server for anyway?
dave
dave
The GUI is going to be a simple display of who's online etc.

How would the two threads communicate, via a socket?

Dave
Dragoncar
Dragoncar
Two options are:

You could have where you are going to store the data avaliable to both threads.

Or you could have a queue that accessable to both threads and then the thread that reads the ports can put messages on the queue and the gui can take them off.
dave
dave
I've decided that i will have the GUI and server code in separate threads and also that i will use sockets to update the data stored in the GUI code, about the ports.

Dave

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.