package org.merry;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MerryApplication extends Application {
public static void main( String[] args ) {
launch();
}
@Override
public void start( Stage stage ) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader( MerryApplication.class.getResource( "merry-view.fxml" ) );
Scene scene = new Scene( fxmlLoader.load(), 640, 480 );
stage.setTitle( "Merry XMAS and happy new year!" );
stage.setScene( scene );
stage.show();
}
}
package org.merry;
import javafx.fxml.FXML;
import javafx.scene.effect.DropShadow;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class MerryController {
@FXML
private Text merryText;
@FXML
protected void onMerryButtonClick() {
DropShadow dropShadow = new DropShadow();
dropShadow.setOffsetY( 3.0f );
dropShadow.setColor( Color.color( 0.4f, 0.4f, 0.4f ) );
merryText.setEffect( dropShadow );
merryText.setCache( true );
merryText.setX( 10.0f );
merryText.setY( 270.0f );
merryText.setFill( Color.RED );
merryText.setFont( Font.font( "Verdana", FontWeight.BOLD, 32 ) );
merryText.setText( "Boldog karácsonyt és \nboldog új évet mindenkinek!" );
}
}
//module-info.java
module org.merry {
requires javafx.controls;
requires javafx.fxml;
requires java.desktop;
opens org.merry to javafx.fxml;
exports org.merry;
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- merry-view.fxml -->
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<VBox xmlns:fx="http://javafx.com/fxml" alignment="CENTER" spacing="20.0" style="-fx-background-color: #D8D8C4"
fx:controller="org.merry.MerryController">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
</padding>
<Text fx:id="merryText"/>
<Button text="Start!" onAction="#onMerryButtonClick" style="-fx-font: 22 arial; -fx-base: #b6e7c9;"/>
</VBox>
# build.gradle
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.1'
}
group 'org.merry'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
sourceCompatibility = '17'
targetCompatibility = '17'
tasks.withType( JavaCompile ) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'org.merry'
mainClass = 'org.merry.MerryApplication'
}
javafx {
version = '17.0.1'
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
jlink {
imageZip = project.file( "${buildDir}/distributions/app-${javafx.platform.classifier}.zip" )
options = [ '--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages' ]
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}
# settings.gradle
rootProject.name = "MerryXmas"