Skip to content
Snippets Groups Projects
Commit b8565a90 authored by Hai HoDac's avatar Hai HoDac
Browse files

Merge branch 'mpriymak' of...

Merge branch 'mpriymak' of https://gitlab.eng.unimelb.edu.au/1050369/comp90015-dsass2-infinitymonkeys-remaster into hai

 Conflicts:
	src/client/Client.java
parents afa837e5 7a9d34c7
Branches
Tags
1 merge request!15Hai
...@@ -27,28 +27,26 @@ public class StartScreen { ...@@ -27,28 +27,26 @@ public class StartScreen {
// } // }
ActionListener actionListener = new ActionListener() { ActionListener actionListener = new ActionListener()
public void actionPerformed(ActionEvent e) { {
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == joinButton) if (e.getSource() == joinButton)
{ {
client.setUsername(textField1.getText());
client.setServerAddress(textField2.getText()); client.setServerAddress(textField2.getText());
client.setUsername(textField1.getText());
if( client.connect() ) if( client.connect() )
{ {
frame.setVisible(false); frame.setVisible(false);
frame.dispose(); frame.dispose();
client.run();
} }
else else
{ {
showErrorMessage("Could not connect to server..."); showErrorMessage("Could not connect to server...");
} }
client.
//new ChatScreen(); //new ChatScreen();
} }
} }
......
...@@ -3,7 +3,6 @@ package client; ...@@ -3,7 +3,6 @@ package client;
import remote.IChatController; import remote.IChatController;
import remote.IClientController; import remote.IClientController;
import client.ChatUpdate; import client.ChatUpdate;
import client.DrawingUpdate;
import GUI.StartScreen; import GUI.StartScreen;
import java.rmi.NotBoundException; import java.rmi.NotBoundException;
...@@ -14,6 +13,7 @@ import java.util.concurrent.TimeUnit; ...@@ -14,6 +13,7 @@ import java.util.concurrent.TimeUnit;
public class Client public class Client
{ {
//test
private String userName; private String userName;
private String serverAddress; private String serverAddress;
...@@ -39,6 +39,7 @@ public class Client ...@@ -39,6 +39,7 @@ public class Client
{ {
this.userName = "DefaultUser"; this.userName = "DefaultUser";
this.chatUpdate = new ChatUpdate(); this.chatUpdate = new ChatUpdate();
this.startScreen = new StartScreen(this);
this.drawingUpdate = new DrawingUpdate(); this.drawingUpdate = new DrawingUpdate();
} }
...@@ -55,12 +56,13 @@ public class Client ...@@ -55,12 +56,13 @@ public class Client
} }
} }
public void run() throws RemoteException, NotBoundException public void run()
{ {
connect(); //connect();
try try
{ {
System.out.println("Sleeping...");
TimeUnit.MINUTES.sleep(5); TimeUnit.MINUTES.sleep(5);
} }
catch(Exception e) catch(Exception e)
...@@ -69,24 +71,31 @@ public class Client ...@@ -69,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"); chatController = (IChatController) registryServer.lookup("ChatController");
clientController = (IClientController) registryServer.lookup("ClientController"); clientController = (IClientController) registryServer.lookup("ClientController");
System.out.println(userName + " fetched all controller from RMI registry"); if (clientController.join(userName, this.chatUpdate))
if ( clientController.join(userName, this.chatUpdate, this.drawingUpdate ) )
{ {
System.out.println("Connected to server"); System.out.println("Connected to server");
return true; return true;
} }
}
catch (Exception e)
{
e.printStackTrace();
}
return false; return false;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment