From 4a0115f273a264e9586dd257727aa03027924fef Mon Sep 17 00:00:00 2001 From: gx-huang Date: Sat, 1 Feb 2020 23:35:56 +0800 Subject: [PATCH] Level 10: GUI --- build.gradle | 38 ++++++++++++++++++++----------------- src/main/java/Duke.java | 15 ++++++++++++++- src/main/java/Launcher.java | 11 +++++++++++ 3 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 src/main/java/Launcher.java diff --git a/build.gradle b/build.gradle index a95013e8ca..b0c8b5366d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import org.gradle.api.plugins.internal.DefaultJavaApplication + plugins { id 'java' id 'application' @@ -10,33 +12,35 @@ repositories { mavenCentral() } -application { +final def application = application { // Change this to your main class. - mainClassName = "Duke" -} - -dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0' + mainClassName = "Duke.class" } +application test { useJUnitPlatform() } -/*plugins { - id 'java' - id 'org.openjfx.javafxplugin' version '0.0.7' -} +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0' -repositories { - mavenCentral() + String javaFxVersion = '11' + + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' } -javafx { - version = "11.0.2" - modules = [ 'javafx.controls', 'javafx.fxml' ] -}*/ - run { standardInput = System.in } \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index d2ed2efdf4..7043bfd02d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,5 +1,9 @@ +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.stage.Stage; -public class Duke { +public class Duke extends Application { private DukeStorage storage; private UserText tasks; @@ -21,4 +25,13 @@ public void run() { public static void main(String[] args) throws DukeException { new Duke("data/tasks.txt").run(); } + + @Override + public void start(Stage stage) { + Label helloWorld = new Label("Hello World!"); // Creating a new Label control + Scene scene = new Scene(helloWorld); // Setting the scene to be our Label + + stage.setScene(scene); // Setting the stage to show our screen + stage.show(); // Render the stage. + } } diff --git a/src/main/java/Launcher.java b/src/main/java/Launcher.java new file mode 100644 index 0000000000..68ad0005bc --- /dev/null +++ b/src/main/java/Launcher.java @@ -0,0 +1,11 @@ +import javafx.application.Application; + +/** + * A launcher class to workaround classpath issues. + */ +public class Launcher { + public static void main(String[] args) { + Application.launch(Duke.class, args); + } +} +