diff --git a/src/GUI/ChatScreen.form b/src/GUI/ChatScreen.form index 62e6e34eb874be74427ea0edf4f88a6c4a99be32..05bc77bc7c92c0705b176c7bbc1ab31ab2bf8e08 100644 --- a/src/GUI/ChatScreen.form +++ b/src/GUI/ChatScreen.form @@ -35,7 +35,7 @@ </hspacer> </children> </grid> - <grid id="b37e3" binding="x" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="b37e3" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> @@ -107,10 +107,10 @@ </component> </children> </grid> - <grid id="be22c" binding="ryanPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="c0bac" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> - <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <grid row="0" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> </constraints> <properties/> <border type="none"/> diff --git a/src/GUI/ChatScreen.java b/src/GUI/ChatScreen.java index 86cc5fb5c09a3c3249b83686d7a504d4a6ba44e2..27f9402f9cdc23f1342d0b771eda52d1921b68f0 100644 --- a/src/GUI/ChatScreen.java +++ b/src/GUI/ChatScreen.java @@ -1,12 +1,25 @@ package GUI; +import client.Client; +import remote.IChatController; +import remote.IClientController; + import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.rmi.RemoteException; public class ChatScreen { public JPanel panel2; private JButton quitButton; private JButton send; + + public JTextArea getChatOutputArea() + { + return chatOutputArea; + } + private JTextArea chatOutputArea; private JTextArea chatInputArea; private JTextArea userListArea; @@ -14,16 +27,65 @@ public class ChatScreen { private JPanel x; private JFrame frame; - public ChatScreen(){ + private Client client; + + public void setChatOutput(String message) + { + this.chatOutputArea.setText(message); + } + + ActionListener actionListener = new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + if (e.getSource() == send) + { + String message = chatInputArea.getText(); + chatInputArea.setText(""); + IChatController chatController = client.getChatController(); + try + { + System.out.println("Send button pressed"); + chatController.broadcastMessage(client.getUserName(), message); + } + catch (RemoteException ex) + { + ex.printStackTrace(); + } + } + else if (e.getSource() == quitButton) + { + IClientController clientController = client.getClientController(); + try + { + System.out.println("Quit button pressed"); + clientController.quit(client.getUserName()); + System.exit(0); + } + catch (RemoteException ex) + { + ex.printStackTrace(); + } + } + } + + }; + + public ChatScreen(Client client) + { + this.client = client; + quitButton.addActionListener(actionListener); + send.addActionListener(actionListener); frame = new JFrame("App"); frame.setContentPane(panel2); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); createUIComponents(); - } + + private void createUIComponents() { ryanPanel = new PaintGUI().getGlobal(); diff --git a/src/GUI/StartScreen.java b/src/GUI/StartScreen.java index bb1ec0fe5ef685529ae8f02d632bf93c4d58bbea..6fdb1bdad02e8540b44c4cafefbd81f36830a104 100644 --- a/src/GUI/StartScreen.java +++ b/src/GUI/StartScreen.java @@ -22,13 +22,8 @@ public class StartScreen { this.client = client; } - public StartScreen() { - super(); - } - // public static void main(String[] args) { -// StartScreen startScreen = new StartScreen(); -// startScreen.go(); +// new StartScreen().go(); // } @@ -44,15 +39,14 @@ public class StartScreen { if( client.connect() ) { frame.setVisible(false); -// frame.dispose(); - client.run(); + frame.dispose(); + //client.doSomething(); + new ChatScreen(client); } else { showErrorMessage("Could not connect to server..."); } - - //new ChatScreen(); } } diff --git a/src/client/ChatUpdate.java b/src/client/ChatUpdate.java index 93cce44f87ee930cab1fab6d47f2e560d65d03d8..72682a9249b2ceae23b1a156d620252df2fdd778 100644 --- a/src/client/ChatUpdate.java +++ b/src/client/ChatUpdate.java @@ -8,14 +8,21 @@ import java.rmi.server.UnicastRemoteObject; public class ChatUpdate extends UnicastRemoteObject implements IChatUpdate, Serializable { - public ChatUpdate() throws RemoteException + private Client client; + + public ChatUpdate(Client client) throws RemoteException { super(); + this.client = client; } @Override public boolean notifyChat(String fromClient, String message) throws RemoteException { +// client.getChatScreen().setChatOutput(message); + client.getChatScreen().getChatOutputArea().setText(message); + + //client.setReceivedMessage(message); System.out.println(fromClient + ": " + message); return true; } diff --git a/src/client/Client.java b/src/client/Client.java index 4601865c0c8d078ecb6bd7a3acb8d17f160a3fe3..6a1845d0631815a7f46c925bda139d1f841f03a8 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -1,5 +1,6 @@ package client; +import GUI.ChatScreen; import remote.IChatController; import remote.IClientController; import client.ChatUpdate; @@ -25,11 +26,37 @@ public class Client private StartScreen startScreen; + public ChatScreen getChatScreen() + { + return chatScreen; + } + + private ChatScreen chatScreen; + + + + private String receivedMessage; + + public IChatController getChatController() + { + return chatController; + } + + public IClientController getClientController() + { + return clientController; + } + public void setUsername(String userName) { this.userName = userName; } + public String getUserName() + { + return this.userName; + } + public void setServerAddress(String serverAddress) { this.serverAddress = serverAddress; @@ -38,7 +65,7 @@ public class Client public Client() throws RemoteException { this.userName = "DefaultUser"; - this.chatUpdate = new ChatUpdate(); + this.chatUpdate = new ChatUpdate(this); this.startScreen = new StartScreen(this); this.drawingUpdate = new DrawingUpdate(); } @@ -56,12 +83,13 @@ public class Client } } - public void run() + public void doSomething() { - //connect(); +// new ChatScreen(); try { + new ChatScreen(this); System.out.println("Sleeping..."); TimeUnit.MINUTES.sleep(5); } @@ -95,7 +123,13 @@ public class Client return false; } + public String getReceivedMessage() + { + return receivedMessage; + } - - + public void setReceivedMessage(String receivedMessage) + { + this.receivedMessage = receivedMessage; + } } \ No newline at end of file