diff --git a/src/GUI/icon/circle.png b/resources/circle.png similarity index 100% rename from src/GUI/icon/circle.png rename to resources/circle.png diff --git a/src/GUI/icon/eraser.png b/resources/eraser.png similarity index 100% rename from src/GUI/icon/eraser.png rename to resources/eraser.png diff --git a/src/GUI/icon/freehand.png b/resources/freehand.png similarity index 100% rename from src/GUI/icon/freehand.png rename to resources/freehand.png diff --git a/src/GUI/icon/line.png b/resources/line.png similarity index 100% rename from src/GUI/icon/line.png rename to resources/line.png diff --git a/src/GUI/icon/oval.png b/resources/oval.png similarity index 100% rename from src/GUI/icon/oval.png rename to resources/oval.png diff --git a/src/GUI/icon/palette.png b/resources/palette.png similarity index 100% rename from src/GUI/icon/palette.png rename to resources/palette.png diff --git a/src/GUI/icon/rectangle.png b/resources/rectangle.png similarity index 100% rename from src/GUI/icon/rectangle.png rename to resources/rectangle.png diff --git a/src/GUI/icon/square.png b/resources/square.png similarity index 100% rename from src/GUI/icon/square.png rename to resources/square.png diff --git a/src/GUI/icon/text.png b/resources/text.png similarity index 100% rename from src/GUI/icon/text.png rename to resources/text.png diff --git a/src/GUI/PaintGUI.java b/src/GUI/PaintGUI.java index 9cfdfd948526d341854121303309ab86590923a7..bf6c13b8510f83203590b7b48f3ee1696b5c4447 100644 --- a/src/GUI/PaintGUI.java +++ b/src/GUI/PaintGUI.java @@ -58,24 +58,15 @@ public class PaintGUI extends JPanel { /// Set up button icons /// try { - String path = System.getProperty("user.dir"); - System.out.println(path); - File palettePic = new File(path + "/src/GUI/icon/palette.png"); - File freehandPic = new File(path + "/src/GUI/icon/freehand.png"); - File linePic = new File(path + "/src/GUI/icon/line.png"); - File circlePic = new File(path + "/src/GUI/icon/circle.png"); - File rectPic = new File(path + "/src/GUI/icon/rectangle.png"); - File ovalPic = new File(path + "/src/GUI/icon/oval.png"); - File eraserPic = new File(path + "/src/GUI/icon/eraser.png"); - File textPic = new File(path + "/src/GUI/icon/text.png"); - BufferedImage paletteIcon = ImageIO.read(palettePic); - BufferedImage freehandIcon = ImageIO.read(freehandPic); - BufferedImage lineIcon = ImageIO.read(linePic); - BufferedImage circleIcon = ImageIO.read(circlePic); - BufferedImage rectIcon = ImageIO.read(rectPic); - BufferedImage ovalIcon = ImageIO.read(ovalPic); - BufferedImage eraserIcon = ImageIO.read(eraserPic); - BufferedImage textIcon = ImageIO.read(textPic); + BufferedImage paletteIcon = ImageIO.read(getClass().getResource("/palette.png")); + BufferedImage freehandIcon = ImageIO.read(getClass().getResource("/freehand.png")); + BufferedImage lineIcon = ImageIO.read(getClass().getResource("/line.png")); + BufferedImage circleIcon = ImageIO.read(getClass().getResource("/circle.png")); + BufferedImage rectIcon = ImageIO.read(getClass().getResource("/rectangle.png")); + BufferedImage ovalIcon = ImageIO.read(getClass().getResource("/oval.png")); + BufferedImage eraserIcon = ImageIO.read(getClass().getResource("/eraser.png")); + BufferedImage textIcon = ImageIO.read(getClass().getResource("/text.png")); + colorPaletteBtn = new JButton(new ImageIcon(paletteIcon)); colorPaletteBtn.addActionListener(actionListener); freehandBtn = new JButton(new ImageIcon(freehandIcon)); diff --git a/src/GUI/StartScreen.java b/src/GUI/StartScreen.java index 6b6a4b53bfb7466916b97ed4f06073b92d3c927c..6b030e1fada0d4a4b0576dbc088fd53aa94b93e8 100644 --- a/src/GUI/StartScreen.java +++ b/src/GUI/StartScreen.java @@ -46,43 +46,47 @@ public class StartScreen { String userName = usernameField.getText(); String password = new String(passwordField.getPassword()); - int connectionStatus = client.connect(userName, serverAddress, password); - - if( connectionStatus == 1 ) - { - frame.setVisible(false); - frame.dispose(); - if (client.getApplicationMain().getFrame() == null) { - client.startApplication(); + if (userName.length() <= 15) { + int connectionStatus = client.connect(userName, serverAddress, password); + if( connectionStatus == 1 ) + { + frame.setVisible(false); + frame.dispose(); + if (client.getApplicationMain().getFrame() == null) { + client.startApplication(); + } + else { + client.clearChat(); + client.clearDrawingArea(); + client.setVisibleApplication(); + } + + } + else if( connectionStatus == 2 || connectionStatus == 6 ) + { + showErrorMessage("Duplicate usernameField: Please enter a new usernameField"); + } + else if( connectionStatus == 3 ) + { + showErrorMessage("Cannot connect to server: Please check the server address"); } - else { - client.clearChat(); - client.clearDrawingArea(); + else if( connectionStatus == 4 ) + { + showErrorMessage("Incorrect Password"); + } + else if( connectionStatus == 5 ) + { + frame.setVisible(false); + frame.dispose(); client.setVisibleApplication(); } - - } - else if( connectionStatus == 2 || connectionStatus == 6 ) - { - showErrorMessage("Duplicate usernameField: Please enter a new usernameField"); - } - else if( connectionStatus == 3 ) - { - showErrorMessage("Cannot connect to server: Please check the server address"); - } - else if( connectionStatus == 4 ) - { - showErrorMessage("Incorrect Password"); - } - else if( connectionStatus == 5 ) - { - frame.setVisible(false); - frame.dispose(); - client.setVisibleApplication(); + else + { + showErrorMessage("Unknown Connection Status"); + } } - else - { - showErrorMessage("Unknown Connection Status"); + else { + showErrorMessage("Username must be less or equal to 15 characters"); } } } diff --git a/src/client/Client.java b/src/client/Client.java index a9ca1b3b1ec660e097ede6d0cebefa7401f7738b..acfe956e63539b52110b1831e0570e2d2a1f87c5 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -93,9 +93,9 @@ public class Client } - public Client(String username) throws RemoteException, NoSuchProviderException, NoSuchAlgorithmException + public Client() throws RemoteException, NoSuchProviderException, NoSuchAlgorithmException { - this.defaultUserName = username; + this.defaultUserName = DEFAULT_USERNAME; this.clientUpdate = new ClientUpdate(this); this.chatUpdate = new ChatUpdate(this); this.drawingUpdate = new DrawingUpdate(this); @@ -108,7 +108,7 @@ public class Client { try { - Client client = new Client(args[0]); + Client client = new Client(); client.showStartScreen(); } catch (Exception e) diff --git a/src/server/Server.java b/src/server/Server.java index 9e0084d77316ae0cdabc05dc2755b48cf327bef0..b65b320e1acd0861b99fa9eeb41d0cb345a9c8cc 100644 --- a/src/server/Server.java +++ b/src/server/Server.java @@ -50,7 +50,7 @@ public class Server { Server server = new Server(); - server.run(); + server.run(args[0]); } catch( Exception e ) { @@ -58,15 +58,15 @@ public class Server } } - public void run() throws RemoteException + public void run(String serverIP) throws RemoteException { - String serverIP = ""; - try { - InetAddress inetAddress = InetAddress.getLocalHost(); - serverIP = inetAddress.getHostAddress(); - } catch (Exception e) { - e.printStackTrace(); - } +// String serverIP = ""; +// try { +// InetAddress inetAddress = InetAddress.getLocalHost(); +// serverIP = inetAddress.getHostAddress(); +// } catch (Exception e) { +// e.printStackTrace(); +// } System.setProperty("java.rmi.server.hostname", serverIP); @@ -91,16 +91,18 @@ public class Server System.out.println("Server is ready"); - printIP(); + printIP(serverIP); } - private void printIP() + private void printIP(String serverIP) { InetAddress inetAddress = null; try { - inetAddress = InetAddress.getLocalHost(); + if (serverIP.isEmpty()) { + inetAddress = InetAddress.getLocalHost(); + } else inetAddress = InetAddress.getByName(serverIP); } catch (UnknownHostException e) {