Sign in to follow this  

Java Program Flow

This topic is 4336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this