본문 바로가기
자바

자바 자바fx 달력 만들기(1) 첫번째 예제 [김철수홍길동]

by 세상 모든 것 들은 그 자신을 위해 존재한다. 2021. 2. 9.

소스코드가 많고 길어서 하나씩 나누어서 올리겠습니다.

추후에 올리는 예제를 하나씩 추가하시면 기능이 완성됩니다.

달력을 만들어서 그날에 해당하는 내용을 출력하는 예제로 구성했습니다.

 

사용 예제 ) 코드를 복붙 하여 실행해 보시기 바랍니다.

설명은 주석과 코드 아랫부분에 있습니다.

1. 메인 파일 예제입니다.(title 만 다르고 내용이 거의 변하지 않습니다.)

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("calendar.fxml"));
			Scene scene = new Scene(root);
			primaryStage.setScene(scene);
			
			//창을 항사위에 표시함
			primaryStage.setAlwaysOnTop(true);
			primaryStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		launch(args);
	}

}

2. calendar.fxml 파일 예제입니다.

그대로 복붙 하여 테스트해보시면 됩니다.

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.effect.Blend?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="620.0" prefWidth="620.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Calendar">
   <center>
      <GridPane fx:id="grid" onMousePressed="#clickGrid" prefHeight="620.0" prefWidth="620.0" style="-fx-border-color: BLACK;" BorderPane.alignment="CENTER">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black black; -fx-border-style: segments(3, 3, 3, 3);">
               <children>
                  <HBox fx:id="hbox1" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl00" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: white;" text="7" textFill="#fe4371">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="1">
               <children>
                  <HBox fx:id="hbox2" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl01" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="2">
               <children>
                  <HBox fx:id="hbox3" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl02" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="3">
               <children>
                  <HBox fx:id="hbox4" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl03" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="5">
               <children>
                  <HBox fx:id="hbox6" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl05" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="103.0" prefWidth="193.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="6">
               <children>
                  <HBox fx:id="hbox7" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin>
                  </HBox>
                  <Label fx:id="lbl06" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#4d00ff">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.rowIndex="1">
               <children>
                  <HBox fx:id="hbox8" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl10" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#fe4371">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font>
                  </Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="1" GridPane.rowIndex="1">
               <children>
                  <HBox fx:id="hbox9" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl11" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font>
                  </Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="2" GridPane.rowIndex="1">
               <children>
                  <HBox fx:id="hbox10" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin>
                  </HBox>
                  <Label fx:id="lbl12" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="3" GridPane.rowIndex="1">
               <children>
                  <HBox fx:id="hbox11" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin>
                  </HBox>
                  <Label fx:id="lbl13" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="4" GridPane.rowIndex="1">
               <children>
                  <HBox fx:id="hbox12" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin>
                  </HBox>
                  <Label fx:id="lbl14" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="5" GridPane.rowIndex="1">
               <children>
                  <HBox fx:id="hbox13" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl15" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="6" GridPane.rowIndex="1">
               <children>
                  <HBox fx:id="hbox14" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl16" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#726cf2">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.rowIndex="2">
               <children>
                  <HBox fx:id="hbox15" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl20" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#fe4371">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="1" GridPane.rowIndex="2">
               <children>
                  <HBox fx:id="hbox16" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl21" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="2" GridPane.rowIndex="2">
               <children>
                  <HBox fx:id="hbox17" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl22" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="3" GridPane.rowIndex="2">
               <children>
                  <HBox fx:id="hbox18" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl23" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="4" GridPane.rowIndex="2">
               <children>
                  <HBox fx:id="hbox19" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl24" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="5" GridPane.rowIndex="2">
               <children>
                  <HBox fx:id="hbox20" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl25" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="6" GridPane.rowIndex="2">
               <children>
                  <HBox fx:id="hbox21" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl26" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#726cf2">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.rowIndex="3">
               <children>
                  <HBox fx:id="hbox22" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl30" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#fe4371">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="1" GridPane.rowIndex="3">
               <children>
                  <HBox fx:id="hbox23" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl31" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="2" GridPane.rowIndex="3">
               <children>
                  <HBox fx:id="hbox24" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl32" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="3" GridPane.rowIndex="3">
               <children>
                  <HBox fx:id="hbox25" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl33" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="4" GridPane.rowIndex="3">
               <children>
                  <HBox fx:id="hbox26" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl34" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="5" GridPane.rowIndex="3">
               <children>
                  <HBox fx:id="hbox27" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl35" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="6" GridPane.rowIndex="3">
               <children>
                  <HBox fx:id="hbox28" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl36" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#726cf2">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.rowIndex="4">
               <children>
                  <HBox fx:id="hbox29" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl40" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#fe4371">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="1" GridPane.rowIndex="4">
               <children>
                  <HBox fx:id="hbox30" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl41" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="2" GridPane.rowIndex="4">
               <children>
                  <HBox fx:id="hbox31" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl42" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="3" GridPane.rowIndex="4">
               <children>
                  <HBox fx:id="hbox32" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl43" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="4" GridPane.rowIndex="4">
               <children>
                  <HBox fx:id="hbox33" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl44" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="5" GridPane.rowIndex="4">
               <children>
                  <HBox fx:id="hbox34" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl45" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="6" GridPane.rowIndex="4">
               <children>
                  <HBox fx:id="hbox35" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl46" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#726cf2">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.rowIndex="5">
               <children>
                  <HBox fx:id="hbox36" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl50" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#fe4371">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="1" GridPane.rowIndex="5">
               <children>
                  <HBox fx:id="hbox37" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl51" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="2" GridPane.rowIndex="5">
               <children>
                  <HBox fx:id="hbox38" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl52" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="4" GridPane.rowIndex="5">
               <children>
                  <HBox prefHeight="14.0" prefWidth="143.0">
                     <padding>
                        <Insets top="5.0" />
                     </padding></HBox>
                  <Label fx:id="lbl54" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" top="5.0" />
                     </VBox.margin>
                  </Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="5" GridPane.rowIndex="5">
               <children>
                  <HBox prefHeight="14.0" prefWidth="143.0" />
                  <Label fx:id="lbl55" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
               <padding>
                  <Insets top="5.0" />
               </padding>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="6" GridPane.rowIndex="5">
               <children>
                  <HBox prefHeight="14.0" prefWidth="143.0" />
                  <Label fx:id="lbl56" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7" textFill="#726cf2">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
               <padding>
                  <Insets top="5.0" />
               </padding>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="3" GridPane.rowIndex="5">
               <children>
                  <HBox fx:id="hbox39" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin></HBox>
                  <Label fx:id="lbl53" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <font>
                        <Font size="19.0" />
                     </font>
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin></Label>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-border-color: white black black white; -fx-border-style: segments(3, 3, 3, 3);" GridPane.columnIndex="4">
               <children>
                  <HBox fx:id="hbox5" prefHeight="14.0" prefWidth="143.0">
                     <VBox.margin>
                        <Insets top="5.0" />
                     </VBox.margin>
                  </HBox>
                  <Label fx:id="lbl04" alignment="CENTER_RIGHT" prefWidth="30.0" style="-fx-background-color: WHITE;" text="7">
                     <VBox.margin>
                        <Insets left="5.0" />
                     </VBox.margin>
                     <font>
                        <Font size="19.0" />
                     </font>
                  </Label>
               </children>
            </VBox>
         </children>
         <cursor>
            <Cursor fx:constant="DEFAULT" />
         </cursor>
         <effect>
            <Blend />
         </effect>
         <opaqueInsets>
            <Insets />
         </opaqueInsets>
      </GridPane>
   </center>
   <top>
      <VBox prefHeight="88.0" prefWidth="620.0" BorderPane.alignment="CENTER">
         <children>
            <HBox prefHeight="44.0" prefWidth="620.0" spacing="10.0" style="-fx-border-color: BLACK;">
               <children>
                  <Button fx:id="btnBMonth" mnemonicParsing="false" onAction="#bMonthClick" prefHeight="62.0" prefWidth="120.0" style="-fx-background-radius: 10;" text="◀" textFill="#0032f5">
                     <HBox.margin>
                        <Insets left="80.0" />
                     </HBox.margin>
                     <font>
                        <Font size="18.0" />
                     </font>
                  </Button>
                  <Button fx:id="btnToday" mnemonicParsing="false" onAction="#todayClick" prefHeight="41.0" prefWidth="199.0" style="-fx-background-radius: 10;" text="TOUCH ME" textFill="#133911">
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                     <font>
                        <Font size="18.0" />
                     </font>
                     <padding>
                        <Insets bottom="10.0" left="30.0" right="30.0" top="10.0" />
                     </padding>
                  </Button>
                  <Button fx:id="btnNMonth" mnemonicParsing="false" onAction="#nMonthClick" prefHeight="62.0" prefWidth="120.0" style="-fx-background-radius: 10;" text="▶" textFill="#ee300a">
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                     <font>
                        <Font size="18.0" />
                     </font>
                  </Button>
               </children>
               <padding>
                  <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
               </padding>
            </HBox>
            <HBox prefHeight="26.0" prefWidth="620.0" spacing="1.0" style="-fx-border-color: GRAY;">
               <children>
                  <Label alignment="CENTER" prefHeight="20.0" prefWidth="88.0" style="-fx-border-color: BLACK;" text="SUN" textFill="#dd0700">
                     <font>
                        <Font name="System Bold" size="16.0" />
                     </font>
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                  </Label>
                  <Label alignment="CENTER" prefHeight="20.0" prefWidth="88.0" style="-fx-border-color: BLACK;" text="MON">
                     <font>
                        <Font size="16.0" />
                     </font>
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                  </Label>
                  <Label alignment="CENTER" prefHeight="20.0" prefWidth="88.0" style="-fx-border-color: BLACK;" text="TUE">
                     <font>
                        <Font size="16.0" />
                     </font>
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                  </Label>
                  <Label alignment="CENTER" prefWidth="88.0" style="-fx-border-color: BLACK;" text="WED">
                     <font>
                        <Font size="16.0" />
                     </font>
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                  </Label>
                  <Label alignment="CENTER" prefWidth="88.0" style="-fx-border-color: BLACK;" text="THU">
                     <font>
                        <Font size="16.0" />
                     </font>
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                  </Label>
                  <Label alignment="CENTER" prefHeight="20.0" prefWidth="88.0" style="-fx-border-color: BLACK;" text="FRI">
                     <font>
                        <Font size="16.0" />
                     </font>
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                  </Label>
                  <Label alignment="CENTER" prefHeight="20.0" prefWidth="88.0" style="-fx-border-color: BLACK;" text="SAT" textFill="#0b009e">
                     <font>
                        <Font size="16.0" />
                     </font>
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                  </Label>
               </children>
            </HBox>
         </children>
      </VBox>
   </top>
</BorderPane>

 

3. Calendar.java 핸들러 파일입니다.

그대로 복붙 하여 테스트하시길 바랍니다.

첫페이지는 기본적인 변수 부분과 initialize 부분을 올립니다.

나머지는 순서대로 올리겠습니다.

 

import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Calendar implements Initializable {

	// 달력을 표시할 그리드 입니다.
	@FXML
	private GridPane grid;

	// 일자별 데이터를 표시할 HBox 입니다.
	@FXML
	private HBox hbox1, hbox2, hbox3, hbox4, hbox5, hbox6, hbox7, hbox8, hbox9, hbox10, hbox11, hbox12, hbox13, hbox14,
			hbox15, hbox16, hbox17, hbox18, hbox19, hbox20, hbox21, hbox22, hbox23, hbox24, hbox25, hbox26, hbox27,
			hbox28, hbox29, hbox30, hbox31, hbox32, hbox33, hbox34, hbox35, hbox36, hbox37, hbox38, hbox39;

	// 날자를 표시할 라벨 입니다.
	@FXML
	private Label lbl00, lbl01, lbl02, lbl03, lbl04, lbl05, lbl06, lbl10, lbl11, lbl12, lbl13, lbl14, lbl15, lbl16,
			lbl20, lbl21, lbl22, lbl23, lbl24, lbl25, lbl26, lbl30, lbl31, lbl32, lbl33, lbl34, lbl35, lbl36, lbl40,
			lbl41, lbl42, lbl43, lbl44, lbl45, lbl46, lbl50, lbl51, lbl52, lbl54, lbl55, lbl56, lbl53;

	// 라벨과 hbox를 배열로 정합니다.
	public Label[] labelList;
	public HBox[] hboxList;

	// 월단위를 뒤로 가는 버튼
	@FXML
	private Button btnBMonth;

	// 현재 년도와 달을 표시하는 버튼과 현재의 달로 바로 돌아오는 버튼 입니다.
	@FXML
	private Button btnToday;

	// 월단위를 앞으로 가는 버튼
	@FXML
	private Button btnNMonth;

	// 현재의 년과 월을 구합니다.
	private LocalDateTime date = LocalDateTime.now();
	int currentYear = date.getYear();
	int currentMonthInt = date.getMonthValue();

	// 월의 첫번째 요일과 마지막 요일을 저장할부분
	YearMonth firstAndLastDay;
	// 첫번째날의 요일
	String strFirstWeek;
	// 마지막날의 요일
	String strLastWeek;
	// -----------------날짜의 칸을 클릭했을때 값을 받아오는
	String clickDate;

	// 오늘날짜를 깜빡이게 하고 멈추게 하기 위해서 사용합니다.
	public Boolean booStopBlink = true;

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// hbox를 리스트로 만들어 일자별 데이터를 표시할때 사용합니다.
		hboxList = new HBox[] { hbox1, hbox2, hbox3, hbox4, hbox5, hbox6, hbox7, hbox8, hbox9, hbox10, hbox11, hbox12,
				hbox13, hbox14, hbox15, hbox16, hbox17, hbox18, hbox19, hbox20, hbox21, hbox22, hbox23, hbox24, hbox25,
				hbox26, hbox27, hbox28, hbox29, hbox30, hbox31, hbox32, hbox33, hbox34, hbox35, hbox36, hbox37, hbox38,
				hbox39 };

		// 라벨을 리스트로 만들어 날자를 표시할때 사용합니다.
		labelList = new Label[] { lbl00, lbl01, lbl02, lbl03, lbl04, lbl05, lbl06, lbl10, lbl11, lbl12, lbl13, lbl14,
				lbl15, lbl16, lbl20, lbl21, lbl22, lbl23, lbl24, lbl25, lbl26, lbl30, lbl31, lbl32, lbl33, lbl34, lbl35,
				lbl36, lbl40, lbl41, lbl42, lbl43, lbl44, lbl45, lbl46, lbl50, lbl51, lbl52, lbl53, lbl54, lbl55,
				lbl56 };

		}
    }

이번 예제는 준비과정의 예제입니다.

다음 예제는 시간되는 데로 계속 올릴 예정 입니다.

 

 

세상모든 것 들은 그 자신을 위해 존재한다.

 

 

728x90
반응형

댓글