From 74c1555794ff07f83dd6080ea45ad5bae45ed00e Mon Sep 17 00:00:00 2001 From: hguandl Date: Mon, 6 Nov 2017 16:38:37 +0800 Subject: [PATCH 1/2] Add the templete. --- src/Main.java | 25 +++++++++++++++++++++++++ src/MainUIxml.java | 38 ++++++++++++++++++++++++++++++++++++++ src/Makefile | 10 ++++++++++ src/mainUI.fxml | 11 +++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/Main.java create mode 100644 src/MainUIxml.java create mode 100644 src/Makefile create mode 100644 src/mainUI.fxml diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..948bf5e --- /dev/null +++ b/src/Main.java @@ -0,0 +1,25 @@ +import javafx.application.Application; +import javafx.stage.Stage; +import javafx.scene.Scene; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; + + +public class Main extends Application { + @Override + public void start(Stage primaryStage) { + try { + Parent root = FXMLLoader.load(getClass().getResource("mainUI.fxml")); + + primaryStage.setTitle("Java 2 Proj - Stage 1"); + primaryStage.setScene(new Scene(root)); + primaryStage.show(); + } catch(Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/MainUIxml.java b/src/MainUIxml.java new file mode 100644 index 0000000..44268eb --- /dev/null +++ b/src/MainUIxml.java @@ -0,0 +1,38 @@ +import java.net.URL; +import java.util.Random; +import java.util.ResourceBundle; + +import javafx.fxml.Initializable; +import javafx.geometry.Rectangle2D; +import javafx.scene.Node; +import javafx.scene.input.MouseEvent; +import javafx.stage.Screen; +import javafx.stage.Stage; + +public class MainUIxml implements Initializable { + private Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds(); + private static Random rand_generator; + private double x; + private double y; + + @Override + public void initialize(URL location, ResourceBundle resources) { + rand_generator = new Random(); + } + + public void moveWindow(MouseEvent me) { + Node node = (Node) me.getSource(); + Stage stage = (Stage) node.getScene().getWindow(); + double height = screenBounds.getHeight(); + double width = screenBounds.getWidth(); + + double x_move = width / 10 + rand_generator.nextDouble() * width / 2; + double y_move = height / 10 + rand_generator.nextDouble() * height / 2; + + this.x = (double) ((long) (this.x + x_move) % (long) (width - stage.getWidth())); + this.y = (double) ((long) (this.y + y_move) % (long) (height - stage.getHeight())); + stage.setX(this.x); + stage.setY(this.y); + } + +} diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..92598b2 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,10 @@ +all : Main.class + +mainUI.class : src/mainUI.java + @javac -d ../bin mainUI.java + +mainUI.class : src/mainUI.java + @javac -d ../bin Main.java + +clean : + rm -f ../bin/*.class \ No newline at end of file diff --git a/src/mainUI.fxml b/src/mainUI.fxml new file mode 100644 index 0000000..c9b8fae --- /dev/null +++ b/src/mainUI.fxml @@ -0,0 +1,11 @@ + + + + + + + + + + + -- Gitee From b91065e860f85d289e8381009b5e2019584a1b6d Mon Sep 17 00:00:00 2001 From: hguandl Date: Wed, 29 Nov 2017 01:58:43 +0800 Subject: [PATCH 2/2] date picker --- Makefile | 25 ++++++++++++++++++++++ src/Main.java | 2 -- src/MainUIxml.java | 47 ++++++++++++++++++++-------------------- src/Makefile | 13 +++++++----- src/mainUI.fxml | 53 +++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 107 insertions(+), 33 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9268327 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +DIR_SRC =./src +DIR_BIN =./bin + +SRC =$(wildcard ${DIR_SRC}/*.java) +OBJ =$(patsubst ${DIR_SRC}/%.java, ${DIR_BIN}/%.class, ${SRC}) +RES =$(patsubst ${DIR_SRC}/%, ${DIR_BIN}/%, $(wildcard ${DIR_SRC}/*.css ${DIR_SRC}/*.fxml)) + +all: $(OBJ) $(RES) + +${DIR_BIN}/%.class: ${DIR_SRC}/%.java + javac -d ${DIR_BIN} $< + +$(DIR_BIN)/%.css: $(DIR_SRC)/%.css + cp -f $^ ./bin + +$(DIR_BIN)/%.fxml: $(DIR_SRC)/%.fxml + cp -f $^ ./bin + +.PHONY: run clean + +run: all + @cd ./bin && java Main + +clean: + -rm -f $(BIN_TARGET) $(DIR_BIN)/*.class $(DIR_BIN)/*.css $(DIR_BIN)/*.fxml \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index 948bf5e..afa4da4 100644 --- a/src/Main.java +++ b/src/Main.java @@ -4,13 +4,11 @@ import javafx.scene.Scene; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; - public class Main extends Application { @Override public void start(Stage primaryStage) { try { Parent root = FXMLLoader.load(getClass().getResource("mainUI.fxml")); - primaryStage.setTitle("Java 2 Proj - Stage 1"); primaryStage.setScene(new Scene(root)); primaryStage.show(); diff --git a/src/MainUIxml.java b/src/MainUIxml.java index 44268eb..facc1df 100644 --- a/src/MainUIxml.java +++ b/src/MainUIxml.java @@ -8,31 +8,32 @@ import javafx.scene.Node; import javafx.scene.input.MouseEvent; import javafx.stage.Screen; import javafx.stage.Stage; +import javafx.scene.control.*; +import java.time.LocalDate; + +import javafx.fxml.FXML; public class MainUIxml implements Initializable { private Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds(); - private static Random rand_generator; - private double x; - private double y; - - @Override - public void initialize(URL location, ResourceBundle resources) { - rand_generator = new Random(); - } - - public void moveWindow(MouseEvent me) { - Node node = (Node) me.getSource(); - Stage stage = (Stage) node.getScene().getWindow(); - double height = screenBounds.getHeight(); - double width = screenBounds.getWidth(); - - double x_move = width / 10 + rand_generator.nextDouble() * width / 2; - double y_move = height / 10 + rand_generator.nextDouble() * height / 2; + private static Random rand_generator; + private double x; + private double y; - this.x = (double) ((long) (this.x + x_move) % (long) (width - stage.getWidth())); - this.y = (double) ((long) (this.y + y_move) % (long) (height - stage.getHeight())); - stage.setX(this.x); - stage.setY(this.y); - } - + @Override + public void initialize(URL location, ResourceBundle resources) { + rand_generator = new Random(); + } + + @FXML + private DatePicker dp1; + private DatePicker dp2; + + @FXML + public void showText() { + LocalDate date = dp1.getValue(); + System.out.printf("%d--%d--%d\n", date.getYear(), date.getMonthValue(), date.getDayOfMonth()); + //System.out.println(dp1.getValue()); + //String s = dp1.getV(); + //System.out.println(s); + } } diff --git a/src/Makefile b/src/Makefile index 92598b2..74bf30e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,10 +1,13 @@ all : Main.class -mainUI.class : src/mainUI.java - @javac -d ../bin mainUI.java +MainUIxml.class : MainUIxml.java + @javac MainUIxml.java -mainUI.class : src/mainUI.java - @javac -d ../bin Main.java +Main.class : Main.java MainUIxml.class + @javac Main.java + +run : Main.class + @java Main clean : - rm -f ../bin/*.class \ No newline at end of file + -rm -f *.class \ No newline at end of file diff --git a/src/mainUI.fxml b/src/mainUI.fxml index c9b8fae..8401909 100644 --- a/src/mainUI.fxml +++ b/src/mainUI.fxml @@ -1,11 +1,58 @@ + + + + + - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- Gitee