Skip to content

Commit

Permalink
Add javafx template
Browse files Browse the repository at this point in the history
  • Loading branch information
buracchi committed Dec 5, 2020
1 parent 75116f1 commit db5649a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 13 deletions.
8 changes: 7 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@

plugins {
id("com.ttbmp.cinehub.java-application-conventions")
id("org.openjfx.javafxplugin") version "0.0.9"
}

dependencies {
implementation(project(":core"))
implementation(project(":data"))
}

javafx {
version = "15.0.1"
modules("javafx.controls", "javafx.fxml")
}

application {
// Define the main class for the application.
mainClass.set("com.ttbmp.cinehub.app.Example")
mainClass.set("com.ttbmp.cinehub.app.CinehubApplication")
}
26 changes: 26 additions & 0 deletions app/src/main/java/com/ttbmp/cinehub/app/CinehubApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ttbmp.cinehub.app;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class CinehubApplication extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("scene.fxml"));

Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("styles.css").toExternalForm());

primaryStage.setTitle("Cinehub");
primaryStage.setScene(scene);
primaryStage.show();
}
}
10 changes: 0 additions & 10 deletions app/src/main/java/com/ttbmp/cinehub/app/Example.java

This file was deleted.

15 changes: 15 additions & 0 deletions app/src/main/java/com/ttbmp/cinehub/app/FXMLController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ttbmp.cinehub.app;

import javafx.fxml.FXML;
import javafx.scene.control.Label;

public class FXMLController {

@FXML
private Label label;

public void initialize() {
label.setText(MessageUtils.getMessage());
}

}
10 changes: 9 additions & 1 deletion app/src/main/java/com/ttbmp/cinehub/app/MessageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
package com.ttbmp.cinehub.app;

class MessageUtils {

private MessageUtils() {

}

public static String getMessage() {
return "Hello world!";
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
return "Hello, JavaFX " + javafxVersion + "\nRunning on Java " + javaVersion + ".";
}

}
11 changes: 11 additions & 0 deletions app/src/main/resources/com/ttbmp/cinehub/app/scene.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.StackPane?>


<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ttbmp.cinehub.app.FXMLController">
<children>
<Label fx:id="label" text="Label" />
</children>
</StackPane>
4 changes: 4 additions & 0 deletions app/src/main/resources/com/ttbmp/cinehub/app/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.label {
-fx-text-fill: #FAB100;
-fx-font-weight: bold;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

public class MessageUtilsTest {
@Test public void testGetMessage() {
assertEquals("Hello world!", MessageUtils.getMessage());
String message = "Hello, JavaFX " +
System.getProperty("javafx.version") +
"\nRunning on Java " +
System.getProperty("java.version") +
".";
assertEquals(message, MessageUtils.getMessage());
}
}

0 comments on commit db5649a

Please sign in to comment.