Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

server values

 
angelpres
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks.

New user.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic