Skip to content

Commit 9d44665

Browse files
committed
添加退出确定界面。
1 parent 420e6f8 commit 9d44665

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

src/main/java/com/xwintop/xJavaFxTool/Main.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.xwintop.xJavaFxTool.utils.Config;
66
import com.xwintop.xJavaFxTool.utils.JavaFxViewUtil;
77
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
8+
import com.xwintop.xcore.util.javafx.AlertUtil;
89
import javafx.application.Application;
910
import javafx.event.EventHandler;
1011
import javafx.fxml.FXMLLoader;
@@ -48,7 +49,9 @@ public void start(Stage primaryStage) throws Exception {
4849
Parent root = fXMLLoader.load();
4950
JFXDecorator decorator = JavaFxViewUtil.getJFXDecorator(primaryStage, resourceBundle.getString("Title") + Config.xJavaFxToolVersions, "/images/icon.jpg", root);
5051
decorator.setOnCloseButtonAction(() -> {
51-
System.exit(0);
52+
if (AlertUtil.showConfirmAlert("确定要退出吗?")) {
53+
System.exit(0);
54+
}
5255
});
5356
Scene scene = JavaFxViewUtil.getJFXDecoratorScene(decorator);
5457
// Scene scene = new Scene(root);
@@ -61,7 +64,11 @@ public void start(Stage primaryStage) throws Exception {
6164
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
6265
@Override
6366
public void handle(WindowEvent event) {
64-
System.exit(0);
67+
if (AlertUtil.showConfirmAlert("确定要退出吗?")) {
68+
System.exit(0);
69+
} else {
70+
event.consume();
71+
}
6572
}
6673
});
6774

src/main/java/com/xwintop/xJavaFxTool/controller/littleTools/TimeToolController.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ private void initEvent() {
5959
}
6060

6161
private void initService() {
62-
JavaFxViewUtil.setPropertyAddChangeListener(textFileldTimeStr, () -> {
63-
convert(null);
64-
});
65-
JavaFxViewUtil.setPropertyAddChangeListener(textFileldTimeStr2, () -> {
66-
revert(null);
67-
});
62+
JavaFxViewUtil.setPropertyAddChangeListener(textFileldTimeStr, this::convert);
63+
JavaFxViewUtil.setPropertyAddChangeListener(textFileldTimeStr2, this::revert);
6864
}
6965

7066
@FXML

src/main/java/com/xwintop/xJavaFxTool/utils/JavaFxViewUtil.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import cn.hutool.core.lang.Singleton;
55
import com.jfoenix.controls.JFXDecorator;
66
import javafx.collections.ObservableList;
7+
import javafx.event.ActionEvent;
78
import javafx.event.Event;
89
import javafx.event.EventHandler;
910
import javafx.fxml.FXMLLoader;
@@ -34,6 +35,7 @@
3435
import java.text.DecimalFormat;
3536
import java.util.HashMap;
3637
import java.util.Map;
38+
import java.util.function.Consumer;
3739

3840
@Log4j
3941
public class JavaFxViewUtil {
@@ -361,11 +363,26 @@ protected void updateItem(String item, boolean empty) {
361363
/**
362364
* 设置改变事件监听操作
363365
*/
364-
public static void setPropertyAddChangeListener(TextInputControl inputControl,Runnable runnable){
366+
public static void setPropertyAddChangeListener(TextInputControl inputControl, Consumer<ActionEvent> consumer) {
367+
inputControl.textProperty().addListener((observable, oldValue, newValue) -> {
368+
if (Singleton.get(TimedCache.class, (long) 2000).get("initiativeChange") != null) {
369+
return;
370+
}
371+
Singleton.get(TimedCache.class, (long) 2000).put("initiativeChange", true);
372+
consumer.accept(null);
373+
Singleton.get(TimedCache.class, (long) 2000).remove("initiativeChange");
374+
});
375+
}
376+
377+
/**
378+
* 设置改变事件监听操作
379+
*/
380+
public static void setPropertyAddChangeListener(TextInputControl inputControl, Runnable runnable) {
365381
inputControl.textProperty().addListener((observable, oldValue, newValue) -> {
366382
setPropertyChangeRun(runnable);
367383
});
368384
}
385+
369386
/**
370387
* 设置改变事件监听防重复操作
371388
*/

0 commit comments

Comments
 (0)