开发者

java - update client GUIs

I am trying to make a Texas Holdem LAN game. Game flow is finished and I am now starting server/client-communication using sockets. My question is this:

What is the best way to update changes to the table (player folds etc.) in the clients GUI's? Is there a favored consept in this situation?

I have a JPanel with the table开发者_Python百科, communitycards, players etc. - Is it possible (or a good idea) to regularly send this JPanel to the clients?


why send the whole jPanel? that is too much going over the socket.

Just send enough information for each clients GUI to repaint the table themselves.


You want to make use of SwingUtilities.invokeLater

In your client code where it is communicating with the server and receiving data based on which you want to update your UI elements, do something like -


public void clientSideOfClientServerCommunication(final someClass someData){
  SwingUtilities.invokeLater(new Runnable(){
    public void run(){
      //use someData to update GUI elements.
    }
  });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜