diff --git a/src/GUI/StartScreen.form b/src/GUI/StartScreen.form index 8cf5813c7b2c4cc1c53fc26fd8ac241e8d5b3284..f266275f5779005b91d96dc1a9134323e557dfdb 100644 --- a/src/GUI/StartScreen.form +++ b/src/GUI/StartScreen.form @@ -97,13 +97,15 @@ <text value="Server IP:"/> </properties> </component> - <component id="63209" class="javax.swing.JTextField" binding="textField2" default-binding="true"> + <component id="63209" class="javax.swing.JTextField" binding="textField2"> <constraints> <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> <preferred-size width="150" height="-1"/> </grid> </constraints> - <properties/> + <properties> + <text value=""/> + </properties> </component> </children> </grid> diff --git a/src/GUI/StartScreen.java b/src/GUI/StartScreen.java index aac4e2000a06cc292b6a8e5cf7a2d633b6cbf99c..07d2e010ca09333f2025a2da09186019fe2a9a1b 100644 --- a/src/GUI/StartScreen.java +++ b/src/GUI/StartScreen.java @@ -1,5 +1,7 @@ package GUI; +import client.Client; + import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -13,24 +15,53 @@ public class StartScreen { private JTextField textField2; JFrame frame; + private Client client; - public static void main(String[] args) { - new StartScreen().go(); + public StartScreen(Client client) + { + this.client = client; } +// public static void main(String[] args) { +// new StartScreen().go(); +// } + ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { - if (e.getSource() == joinButton) { - frame.setVisible(false); - frame.dispose(); - new ChatScreen(); + if (e.getSource() == joinButton) + { + client.setUsername(textField1.getText()); + client.setServerAddress(textField2.getText()); + + if( client.connect() ) + { + frame.setVisible(false); + frame.dispose(); + } + else + { + showErrorMessage("Could not connect to server..."); + } + + + + + client. + + //new ChatScreen(); } } }; - private void go(){ + private void showErrorMessage(String message) + { + JOptionPane.showMessageDialog(null, + message, "Error", JOptionPane.PLAIN_MESSAGE); + } + + public void go(){ joinButton.addActionListener(actionListener); frame = new JFrame("App"); frame.setContentPane(panel1); diff --git a/src/client/Client.java b/src/client/Client.java index c7fa70509fb563ce4a3b1dd8fdedbca235ef8e5c..96f12644bc83fb3226a20b74420f57a8cbf80487 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -3,6 +3,7 @@ package client; import remote.IChatController; import remote.IClientController; import client.ChatUpdate; +import GUI.StartScreen; import java.rmi.NotBoundException; import java.rmi.RemoteException; @@ -14,23 +15,40 @@ public class Client { //test private String userName; + private String serverAddress; + private Registry registryServer; private IChatController chatController; private IClientController clientController; private ChatUpdate chatUpdate; + private DrawingUpdate drawingUpdate; + + private StartScreen startScreen; - public Client(String userName) throws RemoteException + public void setUsername(String userName) { this.userName = userName; + } + + public void setServerAddress(String serverAddress) + { + this.serverAddress = serverAddress; + } + + public Client() throws RemoteException + { + this.userName = "DefaultUser"; this.chatUpdate = new ChatUpdate(); + this.startScreen = new StartScreen(this); + this.drawingUpdate = new DrawingUpdate(); } public static void main(String[] args) { try { - Client client1 = new Client("Max"); - client1.run(); + Client client = new Client(); + client.startScreen.go(); } catch (Exception e) { @@ -63,7 +81,7 @@ public class Client if ( clientController.join(userName, this.chatUpdate ) ) { - System.out.println(userName + " registered at server"); + System.out.println("Connected to server"); return true; } diff --git a/src/client/Client2.java b/src/client/Client2.java index 03075efa8826950e8c72b00ba988cc05b767357d..3eda56bbcb3ba7adc889775fffdd352da89fe084 100644 --- a/src/client/Client2.java +++ b/src/client/Client2.java @@ -41,6 +41,8 @@ public class Client2 { connect(); + chatController.broadcast(userName, "Hello"); + try { TimeUnit.MINUTES.sleep(5); diff --git a/src/server/ChatController.java b/src/server/ChatController.java index b5432e4a8b3487c79c8e847952d8debeebb94bc7..73e114b2ac656ba0aed4f85e6e8984b44d5693e9 100644 --- a/src/server/ChatController.java +++ b/src/server/ChatController.java @@ -19,21 +19,18 @@ public class ChatController extends UnicastRemoteObject implements IChatControll @Override public boolean broadcast(String fromClient, String message) throws RemoteException { - System.out.print("Broadcasting message to everyone"); + System.out.print("Broadcasting message to everyone..."); IChatUpdate client; for( User u : server.users ) { - if( !u.getUserName().equals(fromClient) ) - { - client = u.getIChatUpdate(); + client = u.getIChatUpdate(); - client.notify(fromClient, message); - } + client.notify(fromClient, message); } - System.out.print("Message has been broadcast to everyone"); + System.out.print("...DONE\n"); return true; }