rootProject.name = 'GradleFX'
include('app')
project(":app").name = "GradleJavaFX"
build.gradle
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.11'
}
/*java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
vendor = JvmVendorSpec.ADOPTOPENJDK
}
}*/
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
def currentOS = org.gradle.internal.os.OperatingSystem.current()
def platform
if (currentOS.isWindows()) {
platform = 'win'
}else if (currentOS.isMacOsX()) {
platform = 'mac'
}
else{
platform = 'linux'
}
javafx {
version = "18-ea+10"
modules = ['javafx.controls']
}
dependencies {
// Use JUnit Jupiter for testing.
// testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
// This dependency is used by the application.
//implementation 'com.google.guava:guava:30.1.1-jre'
runtimeOnly "org.openjfx:javafx-graphics:18-ea+10:${platform}"
runtimeOnly "org.openjfx:javafx-base:18-ea+10:${platform}"
runtimeOnly "org.openjfx:javafx-controls:18-ea+10:${platform}"
runtimeOnly "org.openjfx:javafx-fxml:18-ea+10:${platform}"
runtimeOnly "org.openjfx:javafx-swing:18-ea+10:${platform}"
runtimeOnly "org.openjfx:javafx-media:18-ea+10:${platform}"
runtimeOnly "org.openjfx:javafx-web:18-ea+10:${platform}"
}
mainClassName = 'GradleFX.App'
application {
// Define the main class for the application.
mainClass = mainClassName
}
jar {
manifest {
attributes( 'Main-Class': mainClassName)
}
from {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
UtilAlert
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
public class UtilAlert {
private String Title = "";
private String HeaderText = "";
/**
* * * @param Title Alert Title
*/
public void setTitle(String Title) {
this.Title = Title;
}
/**
* * * @return Alert Title
*/
public String getTitle() {
return this.Title;
}
/**
* * * @param HeaderText Alert HeaderText
*/
public void seHeaderText(String HeaderText) {
this.HeaderText = HeaderText;
}
/**
* * * @return Alert HeaderText
*/
public String getHeaderText() {
return this.HeaderText;
}
/**
* * * @param Title Alert Title * @param HeaderText Alert HeaderText
*/
public UtilAlert(String Title, String HeaderText) {
this.Title = Title;
this.HeaderText = HeaderText;
}
/**
* *
*/
public UtilAlert() {
}
/**
* * * @param at AlertType Kiểu hộp thoại * @param string Nội dung trên hộp
* thoại * @param bts ButtonType Các nút lệnh trên hộp thoại * @return
*/
public ButtonType showAndWait(AlertType at, String string, ButtonType... bts) {
Alert alert = new Alert(at, string, bts);
this.setButtonTypeText(bts, alert);
alert.setTitle(this.Title);
alert.setHeaderText(this.HeaderText);
ButtonType buttonType = alert.showAndWait().get();
return buttonType;
}
/**
* * * @param at AlertType Kiểu hộp thoại * @param string Nội dung trên hộp
* thoại * @param bts ButtonType Các nút lệnh trên hộp thoại
*/
public void Show(AlertType at, String string, ButtonType... bts) {
Alert alert = new Alert(at, string, bts);
this.setButtonTypeText(bts, alert);
alert.setTitle(this.Title);
alert.setHeaderText(this.HeaderText);
alert.show();
}
private void setButtonTypeText(ButtonType[] bts, Alert alert) {
for (ButtonType buttonType : bts) {
if (buttonType == ButtonType.YES) {
((Button) alert.getDialogPane().lookupButton(ButtonType.YES)).setText("_Có");
((Button) alert.getDialogPane().lookupButton(ButtonType.YES)).setMnemonicParsing(true);
}
if (buttonType == ButtonType.NO) {
((Button) alert.getDialogPane().lookupButton(ButtonType.NO)).setText("_Không");
((Button) alert.getDialogPane().lookupButton(ButtonType.NO)).setMnemonicParsing(true);
}
if (buttonType == ButtonType.CANCEL) {
((Button) alert.getDialogPane().lookupButton(ButtonType.CANCEL)).setText("_Hủy");
((Button) alert.getDialogPane().lookupButton(ButtonType.CANCEL)).setMnemonicParsing(true);
}
if (buttonType == ButtonType.OK) {
((Button) alert.getDialogPane().lookupButton(ButtonType.OK)).setText("_OK");
((Button) alert.getDialogPane().lookupButton(ButtonType.OK)).setMnemonicParsing(true);
}
if (buttonType == ButtonType.CLOSE) {
((Button) alert.getDialogPane().lookupButton(ButtonType.CLOSE)).setText("Đó_ng");
((Button) alert.getDialogPane().lookupButton(ButtonType.CLOSE)).setMnemonicParsing(true);
}
if (buttonType == ButtonType.APPLY) {
((Button) alert.getDialogPane().lookupButton(ButtonType.APPLY)).setText("_Áp dụng");
((Button) alert.getDialogPane().lookupButton(ButtonType.APPLY)).setMnemonicParsing(true);
}
if (buttonType == ButtonType.FINISH) {
((Button) alert.getDialogPane().lookupButton(ButtonType.FINISH)).setText("_Kết thúc");
((Button) alert.getDialogPane().lookupButton(ButtonType.FINISH)).setMnemonicParsing(true);
}
if (buttonType == ButtonType.PREVIOUS) {
((Button) alert.getDialogPane().lookupButton(ButtonType.PREVIOUS)).setText("T_rước");
((Button) alert.getDialogPane().lookupButton(ButtonType.PREVIOUS)).setMnemonicParsing(true);
}
if (buttonType == ButtonType.NEXT) {
((Button) alert.getDialogPane().lookupButton(ButtonType.NEXT)).setText("_Tiếp");
((Button) alert.getDialogPane().lookupButton(ButtonType.NEXT)).setMnemonicParsing(true);
}
}
}
}
frmMain
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package GradleFX;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
/**
*
* @author admin
*/
public class frmMain extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
UtilAlert abert = new UtilAlert("Thoát khỏi hệ thống", "Thoát khỏi hệ thống và đóng tất cả các của sổ");
primaryStage.setTitle("Gradle JavaFX Java Desktop Application");
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
l.setFont(new Font("Times New Roman", 18));
Scene scene = new Scene(new StackPane(l), 800, 600);
primaryStage.setScene(scene);
primaryStage.setMaximized(true);
primaryStage.centerOnScreen();
primaryStage.show();
primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> {
primaryStage.setMaximized(true);
});
primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> {
primaryStage.setMaximized(true);
});
primaryStage.setOnCloseRequest(
(WindowEvent e) -> {
ButtonType buttonType = abert.showAndWait(Alert.AlertType.CONFIRMATION, "", ButtonType.YES, ButtonType.NO);
if (buttonType == ButtonType.YES) {
primaryStage.close();
Platform.exit();
System.exit(0);
} else {
e.consume();
}
}
);
primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, ev
-> {
if (ev.getCode() == KeyCode.ESCAPE) {
ButtonType buttonType = abert.showAndWait(Alert.AlertType.CONFIRMATION, "", ButtonType.YES, ButtonType.NO);
if (buttonType == ButtonType.YES) {
primaryStage.close();
Platform.exit();
Platform.setImplicitExit(true);
System.exit(0);
} else {
ev.consume();
}
}
}
);
}
@Override
public void init() {
}
@Override
public void stop() {
}
public static void main(String[] args) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> System.out.println("Shutdown hook")));
Application.launch(args);
}
}
App
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package GradleFX;
public class App {
public static void main(String[] args) {
frmMain.main(args);
}
}
Tác giả: Vàng Văn Quyn
Những tin mới hơn
Những tin cũ hơn
- Click vào nút hiển thị ngày trong tuần hoặc tháng âm lịch để xem chi tiết
- Màu đỏ: Ngày tốt
- Xanh lá: Đầu tháng âm lịch
- Màu vàng: Ngày hiện tại