Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming I am understanding your question correctly, I think it would be beneficial for you to structure your classes a little differently...</p> <p>Each BlackJack object has a client, e.g.</p> <pre><code>public class BlackJack{ private Client client; public BlackJack(){ // Setup Client class, which will be passed to all other classes client = new Client(server, port, username); } </code></pre> <p>Then each Client object has an instance of the GUI classes, e.g.</p> <pre><code>public class Client{ private ChatGUI chatgui; private GameGUI gamegui; Client(String server, int port, String username){ chatgui = new ChatGUI(this); gamegui = new GameGUI(this); } //handle messages from server void onMessageRecieved(String msg){ if(/* the message pertains to the game gui */ ) gamegui.newMessage(msg); else if( /* the message pertains to the chat gui */ ) chatgui.newMessage(msg); } //here you can add functions for the gui classes to call public void sendChat(String chat){ } } </code></pre> <p>then your gui classes could look like...</p> <pre><code>public class ChatGUI{ private JTextArea textarea; private Client client; public ChatGUI(Client c){ client = c; } //receive message/command from server public void newMessage(String msg){ //perform the desired action based on the command } public void sendChat(String msg){ client.sendChat(msg); } } public class GameGUI{ private Client client; public GameGUI(Client c){ client = c; } //receive message/command from server public void newMessage(String msg){ //perform the desired action based on the command } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload