From fd9c6a61abe7db217966593b4b21f043c11feb55 Mon Sep 17 00:00:00 2001 From: Hai HoDac <hhodac@student.unimelb.edu.au> Date: Fri, 25 Oct 2019 13:01:06 +1100 Subject: [PATCH] Restrict username to <= 15 characters. Add "resources" folder to project root, moved "icon" folder into "resource" folder. --- {src/GUI/icon => resources}/circle.png | Bin {src/GUI/icon => resources}/eraser.png | Bin {src/GUI/icon => resources}/freehand.png | Bin {src/GUI/icon => resources}/line.png | Bin {src/GUI/icon => resources}/oval.png | Bin {src/GUI/icon => resources}/palette.png | Bin {src/GUI/icon => resources}/rectangle.png | Bin {src/GUI/icon => resources}/square.png | Bin {src/GUI/icon => resources}/text.png | Bin src/GUI/PaintGUI.java | 27 +++------ src/GUI/StartScreen.java | 70 ++++++++++++---------- 11 files changed, 46 insertions(+), 51 deletions(-) rename {src/GUI/icon => resources}/circle.png (100%) rename {src/GUI/icon => resources}/eraser.png (100%) rename {src/GUI/icon => resources}/freehand.png (100%) rename {src/GUI/icon => resources}/line.png (100%) rename {src/GUI/icon => resources}/oval.png (100%) rename {src/GUI/icon => resources}/palette.png (100%) rename {src/GUI/icon => resources}/rectangle.png (100%) rename {src/GUI/icon => resources}/square.png (100%) rename {src/GUI/icon => resources}/text.png (100%) 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 9cfdfd9..bf6c13b 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 6b6a4b5..6b030e1 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"); } } } -- GitLab