Skip to content
Snippets Groups Projects
Select Git revision
  • 1d724e6d516d76b414bb109dff0d4fc166aa0974
  • master default protected
  • ansibleBranch
  • AURIN
4 results

cluster_setup.sh

Blame
  • Client.java 2.94 KiB
    package client;
    
    import GUI.ChatScreen;
    import GUI.PaintGUI;
    import GUI.StartScreen;
    import remote.IChatController;
    import remote.IClientController;
    import remote.IDrawingController;
    
    import java.rmi.RemoteException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    
    public class Client
    {
        //test
        private String userName;
        private String serverAddress;
    
        private Registry registryServer;
        private IChatController chatController;
        private IClientController clientController;
        private IDrawingController drawingController;
    
        private ClientUpdate clientUpdate;
        private ChatUpdate chatUpdate;
        private DrawingUpdate drawingUpdate;
    
        private StartScreen startScreen;
        private ChatScreen chatScreen;
    //    private PaintGUI paintGUI;
    
    //    public PaintGUI getPaintGUI() {
    //        return paintGUI;
    //    }
    
    
        public ChatScreen getChatScreen()
        {
            return chatScreen;
        }
    
    
    
        private String receivedMessage;
    
        public IChatController getChatController()
        {
            return chatController;
        }
    
        public IClientController getClientController()
        {
            return clientController;
        }
    
        public IDrawingController getDrawingController() { return drawingController; }
    
        public void setUsername(String userName)
        {
            this.userName = userName;
        }
    
        public String getUserName()
        {
            return this.userName;
        }
    
        public void setServerAddress(String serverAddress)
        {
            this.serverAddress = serverAddress;
        }
    
        public Client(String username) throws RemoteException
        {
            this.userName = username;
            this.clientUpdate = new ClientUpdate(this);
            this.chatUpdate = new ChatUpdate(this);
            this.drawingUpdate = new DrawingUpdate(this);
            this.startScreen = new StartScreen(this);
            this.chatScreen = new ChatScreen(this);
    //        this.paintGUI = new PaintGUI(this);
        }
    
        public static void main(String[] args)
        {
            try
            {
                Client client = new Client(args[0]);
                client.connect();
    //            client.startScreen.go();
    //            client.getPaintGUI().showGUI();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    
        public boolean connect()
        {
            try
            {
                registryServer = LocateRegistry.getRegistry(serverAddress);
    
                chatController = (IChatController) registryServer.lookup("ChatController");
                clientController = (IClientController) registryServer.lookup("ClientController");
                drawingController = (IDrawingController) registryServer.lookup("DrawingController");
    
                if (clientController.join(userName, this.chatUpdate, this.drawingUpdate))
                {
                    System.out.println("Connected to server");
    
                    return true;
                }
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
    
            return false;
        }
    }