diff --git a/src/GUI/StartScreen.java b/src/GUI/StartScreen.java index 07d2e010ca09333f2025a2da09186019fe2a9a1b..8c64799bbb8150d20f6d9e5cf24dd8b362554c28 100644 --- a/src/GUI/StartScreen.java +++ b/src/GUI/StartScreen.java @@ -27,28 +27,26 @@ public class StartScreen { // } - ActionListener actionListener = new ActionListener() { - public void actionPerformed(ActionEvent e) { + ActionListener actionListener = new ActionListener() + { + public void actionPerformed(ActionEvent e) + { if (e.getSource() == joinButton) { - client.setUsername(textField1.getText()); client.setServerAddress(textField2.getText()); + client.setUsername(textField1.getText()); if( client.connect() ) { frame.setVisible(false); frame.dispose(); + client.run(); } else { showErrorMessage("Could not connect to server..."); } - - - - client. - //new ChatScreen(); } } diff --git a/src/client/Client.java b/src/client/Client.java index 96f12644bc83fb3226a20b74420f57a8cbf80487..bebb2d0e5256e93865f0d369d4857f0e8122a96e 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -21,7 +21,7 @@ public class Client private IChatController chatController; private IClientController clientController; private ChatUpdate chatUpdate; - private DrawingUpdate drawingUpdate; + //private DrawingUpdate drawingUpdate; private StartScreen startScreen; @@ -40,7 +40,7 @@ public class Client this.userName = "DefaultUser"; this.chatUpdate = new ChatUpdate(); this.startScreen = new StartScreen(this); - this.drawingUpdate = new DrawingUpdate(); + //this.drawingUpdate = new DrawingUpdate(); } public static void main(String[] args) @@ -56,12 +56,13 @@ public class Client } } - public void run() throws RemoteException, NotBoundException + public void run() { - connect(); + //connect(); try { + System.out.println("Sleeping..."); TimeUnit.MINUTES.sleep(5); } catch(Exception e) @@ -70,24 +71,31 @@ public class Client } } - public boolean connect() throws RemoteException, NotBoundException + public boolean connect() { - registryServer = LocateRegistry.getRegistry("localhost"); + try + { + registryServer = LocateRegistry.getRegistry(serverAddress); - chatController = (IChatController) registryServer.lookup("ChatController"); - clientController = (IClientController) registryServer.lookup("ClientController"); + chatController = (IChatController) registryServer.lookup("ChatController"); + clientController = (IClientController) registryServer.lookup("ClientController"); - System.out.println(userName + " fetched all controller from RMI registry"); + if (clientController.join(userName, this.chatUpdate)) + { + System.out.println("Connected to server"); - if ( clientController.join(userName, this.chatUpdate ) ) + return true; + } + } + catch (Exception e) { - System.out.println("Connected to server"); - - return true; + e.printStackTrace(); } return false; } + + } \ No newline at end of file