From 30e421d36721662761718da46a7ae05f0793c529 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 4 Mar 2019 09:37:21 +0100 Subject: [PATCH] Added GUI backbone (login and redirect to main stage) --- OOP-Project.iml | 31 ++++++-- pom.xml | 68 +++++++++++++++++ src/Client/.idea/compiler.xml | 9 +++ src/Client/.idea/modules.xml | 10 +++ src/Client/.idea/modules/Client.iml | 2 + src/Client/.idea/modules/Client.main.iml | 48 ++++++++++++ src/Client/.idea/modules/Client.test.iml | 75 +++++++++++++++++++ src/Client/.idea/vcs.xml | 6 ++ .../src/main/java/hello/Application.java | 13 ++-- src/Client/src/main/java/hello/Message.java | 10 +-- src/Client/src/test/java/ApplicationTest.java | 2 + src/Client/src/test/java/MessageTest.java | 6 +- src/GUI/GUIController.java | 22 ++++++ src/GUI/GUIMain.fxml | 23 ++++++ src/GUI/GUIMain.java | 29 +++++++ src/GUI/GUIStyle.css | 3 + src/GUI/Login.fxml | 21 ++++++ src/GUI/LoginController.java | 63 ++++++++++++++++ src/GUI/LoginStyle.css | 6 ++ src/Server/.idea/encodings.xml | 4 + src/Server/.idea/misc.xml | 7 ++ src/Server/src/main/java/hello/Greeting.java | 2 +- .../main/java/hello/GreetingController.java | 5 +- ...pplication.java => ServerApplication.java} | 6 +- .../src/test/java/GreetingControllerTest.java | 11 +-- src/Server/src/test/java/GreetingTest.java | 13 ++-- ...onTest.java => ServerApplicationTest.java} | 4 +- 27 files changed, 463 insertions(+), 36 deletions(-) create mode 100644 src/Client/.idea/compiler.xml create mode 100644 src/Client/.idea/modules.xml create mode 100644 src/Client/.idea/modules/Client.iml create mode 100644 src/Client/.idea/modules/Client.main.iml create mode 100644 src/Client/.idea/modules/Client.test.iml create mode 100644 src/Client/.idea/vcs.xml create mode 100644 src/GUI/GUIController.java create mode 100644 src/GUI/GUIMain.fxml create mode 100644 src/GUI/GUIMain.java create mode 100644 src/GUI/GUIStyle.css create mode 100644 src/GUI/Login.fxml create mode 100644 src/GUI/LoginController.java create mode 100644 src/GUI/LoginStyle.css create mode 100644 src/Server/.idea/encodings.xml create mode 100644 src/Server/.idea/misc.xml rename src/Server/src/main/java/hello/{Application.java => ServerApplication.java} (62%) rename src/Server/src/test/java/{ApplicationTest.java => ServerApplicationTest.java} (53%) diff --git a/OOP-Project.iml b/OOP-Project.iml index b1907ae..391e562 100644 --- a/OOP-Project.iml +++ b/OOP-Project.iml @@ -2,7 +2,12 @@ - + + + file://$MODULE_DIR$/src/Server/src/main/java/hello/Application.java + file://$MODULE_DIR$/src/Client/src/main/java/hello/Application.java + + @@ -13,20 +18,34 @@ + + - - + + - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 547dea2..74ac535 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,74 @@ spring-boot-autoconfigure 2.0.5.RELEASE + + org.slf4j + slf4j-api + 1.7.25 + + + org.slf4j + slf4j-api + 1.7.25 + + + org.springframework + spring-web + 5.0.9.RELEASE + + + ch.qos.logback + logback-classic + 1.2.3 + + + org.slf4j + slf4j-api + 1.7.25 + + + org.springframework + spring-web + 5.0.9.RELEASE + + + org.springframework + spring-web + 5.0.9.RELEASE + + + org.apache.logging.log4j + log4j-api + 2.10.0 + + + org.testng + testng + RELEASE + compile + + + org.testng + testng + 7.0.0-beta3 + compile + + + junit + junit + 4.13-beta-2 + + + org.junit.jupiter + junit-jupiter-api + RELEASE + compile + + + com.fasterxml.jackson.core + jackson-annotations + 2.9.0 + diff --git a/src/Client/.idea/compiler.xml b/src/Client/.idea/compiler.xml new file mode 100644 index 0000000..3d94435 --- /dev/null +++ b/src/Client/.idea/compiler.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/Client/.idea/modules.xml b/src/Client/.idea/modules.xml new file mode 100644 index 0000000..46edb73 --- /dev/null +++ b/src/Client/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/Client/.idea/modules/Client.iml b/src/Client/.idea/modules/Client.iml new file mode 100644 index 0000000..642f2c3 --- /dev/null +++ b/src/Client/.idea/modules/Client.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/Client/.idea/modules/Client.main.iml b/src/Client/.idea/modules/Client.main.iml new file mode 100644 index 0000000..046df4e --- /dev/null +++ b/src/Client/.idea/modules/Client.main.iml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Client/.idea/modules/Client.test.iml b/src/Client/.idea/modules/Client.test.iml new file mode 100644 index 0000000..ae12b55 --- /dev/null +++ b/src/Client/.idea/modules/Client.test.iml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Client/.idea/vcs.xml b/src/Client/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/src/Client/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Client/src/main/java/hello/Application.java b/src/Client/src/main/java/hello/Application.java index 0f4d931..c194ad3 100644 --- a/src/Client/src/main/java/hello/Application.java +++ b/src/Client/src/main/java/hello/Application.java @@ -1,4 +1,4 @@ -package hello; +package main.java.hello; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,12 +9,14 @@ import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; +/* +Application that connects to the server + */ @SpringBootApplication public class Application { - private static final Logger log = LoggerFactory.getLogger(Application.class); - public static void main(String args[]) { + public static void main(String[] args) { SpringApplication.run(Application.class); } @@ -22,14 +24,11 @@ public class Application { public RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } - @Bean public CommandLineRunner run(RestTemplate restTemplate) throws Exception { return args -> { - Message message = restTemplate.getForObject( - "http://localhost:8080/greeting?name=Ceren", Message.class); + Message message = restTemplate.getForObject("http://localhost:8080/greeting?name=Ceren", Message.class); log.info(message.toString()); - }; } } \ No newline at end of file diff --git a/src/Client/src/main/java/hello/Message.java b/src/Client/src/main/java/hello/Message.java index b02965e..b32368e 100644 --- a/src/Client/src/main/java/hello/Message.java +++ b/src/Client/src/main/java/hello/Message.java @@ -1,4 +1,4 @@ -package hello; +package main.java.hello; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -29,9 +29,9 @@ public class Message { @Override public String toString() { - return "Message{" + - "id='" + id + '\'' + - ", content=" + content + - '}'; + return "Message{" + + "id='" + id + '\'' + + ", content=" + content + + '}'; } } \ No newline at end of file diff --git a/src/Client/src/test/java/ApplicationTest.java b/src/Client/src/test/java/ApplicationTest.java index 25d7734..162aa0f 100644 --- a/src/Client/src/test/java/ApplicationTest.java +++ b/src/Client/src/test/java/ApplicationTest.java @@ -1,3 +1,5 @@ +package test.java; + import org.junit.Test; public class ApplicationTest { diff --git a/src/Client/src/test/java/MessageTest.java b/src/Client/src/test/java/MessageTest.java index b0ad736..c5fb96f 100644 --- a/src/Client/src/test/java/MessageTest.java +++ b/src/Client/src/test/java/MessageTest.java @@ -1,4 +1,8 @@ -import hello.Message; +package test.java; + + + +import main.java.hello.Message; import org.junit.Assert; import org.junit.jupiter.api.Test; diff --git a/src/GUI/GUIController.java b/src/GUI/GUIController.java new file mode 100644 index 0000000..f829230 --- /dev/null +++ b/src/GUI/GUIController.java @@ -0,0 +1,22 @@ +package GUI; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Label; + +public class GUIController { + int pressed; + + //put @FXML to let the fxml file know that it can use this label, + // ind of the same as with @Test in jUnit tests + @FXML + private Label txtLabel; + + public void incrementLabel(ActionEvent event) throws Exception { +// System.out.println("pressed button"); + pressed++; + String labeltext = "Button pressed " + pressed + " times!"; + //set the text of the label to the string above + txtLabel.setText(labeltext); + } +} diff --git a/src/GUI/GUIMain.fxml b/src/GUI/GUIMain.fxml new file mode 100644 index 0000000..94ef759 --- /dev/null +++ b/src/GUI/GUIMain.fxml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/src/GUI/GUIMain.java b/src/GUI/GUIMain.java new file mode 100644 index 0000000..7b85a2b --- /dev/null +++ b/src/GUI/GUIMain.java @@ -0,0 +1,29 @@ +package GUI; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class GUIMain extends Application { + + public static void main(String[] args) { + launch(args); + } + + @Override + public void start(Stage primaryStage) throws Exception { + //link fxml file + Parent root = FXMLLoader.load(getClass().getResource("Login.fxml")); + //set the scene + Scene scene = new Scene(root, 400, 400); + //link the stylesheet with the scene + scene.getStylesheets().add(getClass().getResource("LoginStyle.css").toExternalForm()); + + //show the stagw + primaryStage.setScene(scene); + primaryStage.setTitle("login"); + primaryStage.show(); + } +} diff --git a/src/GUI/GUIStyle.css b/src/GUI/GUIStyle.css new file mode 100644 index 0000000..642022f --- /dev/null +++ b/src/GUI/GUIStyle.css @@ -0,0 +1,3 @@ +.root { + -fx-background-color: #eef9ee; +} \ No newline at end of file diff --git a/src/GUI/Login.fxml b/src/GUI/Login.fxml new file mode 100644 index 0000000..b943647 --- /dev/null +++ b/src/GUI/Login.fxml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + +