diff --git a/duke.txt b/duke.txt new file mode 100644 index 0000000000..8413b14387 --- /dev/null +++ b/duke.txt @@ -0,0 +1 @@ +[T][ ] CS2100 Homework diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 41342b1197..d944f2b9dc 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,5 +1,8 @@ package duke; + +import java.io.IOException; + import javafx.application.Application; import javafx.stage.Stage; @@ -21,8 +24,9 @@ public Duke(String filePath) { /** * Old constructor */ - public Duke() { - String filePath = "../ip/src/main/data/duke.txt"; + public Duke() throws IOException { + //String filePath = "../ip/src/main/data/duke.txt"; + String filePath = "./duke.txt"; tasks = new TaskList(); storage = new Storage(filePath, tasks); storage.startStorage(); @@ -48,8 +52,6 @@ public void start(Stage stage) { Window.addUserInput(); - Window.welcomeMessage(); - } } diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index 46c1b3e69f..f9bdb9a0b4 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -28,9 +28,10 @@ public Storage(String filepath, TaskList tasks) { /** * Starts reading the storage */ - public void startStorage() { + public void startStorage() throws IOException { try { reader = new BufferedReader(new FileReader(filepath)); + Window.welcomeMessage(); String fileLine; while ((fileLine = reader.readLine()) != null) { @@ -44,8 +45,9 @@ public void startStorage() { } reader.close(); } catch (IOException e) { - e.printStackTrace(); - System.out.println("The file named duke.txt does not exist."); + writer = new BufferedWriter(new FileWriter("duke.txt")); + Window.sendMessage("The file duke.txt does not exist. I've just created that file for you. Please close " + + "and reopen the program."); } catch (EmptyDescriptionException e) { //Already handled by EmptyDescriptionException } diff --git a/src/main/java/duke/Window.java b/src/main/java/duke/Window.java index 3b322f575f..450a4f1d9a 100644 --- a/src/main/java/duke/Window.java +++ b/src/main/java/duke/Window.java @@ -148,6 +148,16 @@ public static void welcomeMessage() { dialogContainer.getChildren().add(DialogBox.getDukeDialog(welcomeMessage, dukeImageView, welMessage)); } + /** + * Sends a custom message + */ + public static void sendMessage(String message) { + CircleClip clip = new CircleClip(40, 40, 40); + ImageView dukeImageView = new ImageView(duke); + clip.clip(dukeImageView); + Label welcomeMessage = new Label(message); + dialogContainer.getChildren().add(DialogBox.getDukeDialog(welcomeMessage, dukeImageView, message)); + } /** * Sends error message */