1. Main.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | package application; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) { try { Parent root = FXMLLoader.load(getClass().getResource("Main.fxml")); Scene scene = new Scene(root); scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); } } | cs |
2. Main.fxml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.DatePicker?> <?import javafx.scene.control.Label?> <?import javafx.scene.layout.AnchorPane?> <AnchorPane prefHeight="500.0" prefWidth="500.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.60" fx:controller="application.MainController"> <children> <DatePicker fx:id="dp" editable="false" layoutX="56.0" layoutY="56.0" onAction="#showDate" prefHeight="64.0" prefWidth="387.0" showWeekNumbers="true" /> <Label fx:id="showDateLbl" alignment="CENTER" layoutX="56.0" layoutY="191.0" prefHeight="64.0" prefWidth="387.0" text="Label" /> </children> </AnchorPane> | cs |
3. MainController.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package application; import java.time.LocalDate; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.DatePicker; import javafx.scene.control.Label; public class MainController { @FXML private DatePicker dp; @FXML private Label showDateLbl; public void showDate(ActionEvent event){ LocalDate ld = dp.getValue(); showDateLbl.setText(ld.toString()); } } | cs |
'Java > JavaFx' 카테고리의 다른 글
JavaFX 26. Pie Chart (0) | 2016.08.29 |
---|---|
JavaFX 25. WebView (0) | 2016.08.25 |
JavaFX 23. TableView (1) | 2016.08.25 |
JavaFX 22. RadioButton (0) | 2016.08.25 |
JavaFX 21. CheckBox (0) | 2016.08.25 |