The moose likes Java in General and the fly likes server values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "server values" Watch "server values" New topic

server values


Joined: Dec 06, 2004
Posts: 4
Hi all,

I am trying to display values to a client, on a gui. The values are stored on a server (client and server communicate via sockets). i have a separate class for the gui, so a new instance of this is called from the client each time. how can i get the values from the server to the gui and update the gui when these change on the server?


New user.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
See if this matches your setup:

GUI <----> Client <----> Server

The client periodically calls the server to get new values, and wants to call the GUI to update the display. You mentioned creating a new GUI instance every time around and that seems unusual to me. I'd more expect a window that's always open and updates every once in a while.

You might have a main routine that glues all these things together:

I don't know where you are on the Java path ... have you worked at all with threads? The "client.start()" bit implies that it will run on its own thread. That leaves the GUI responsive to menus and buttons and such.

When it comes time for the client to update the GUI it will probably need to use the SwingUtils.invokeLater() method to put the update on the Swing thread or maybe use the Timer to schedule updates. If you haven't done threads before ask and we can work through the details.

In the advanced forum I'd dive into Model View Controller design and talk about how to make a client (model) that doesn't know anything about the GUI (view). We can go there if you like, but getting it glued together may be enough for now.

See if this is enough to get you started. Feel free to post short bits of code if you get stuck. Keep it fun!

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: server values
It's not a secret anymore!