Java FX ๊ฐ๋ฐ ํ๊ฒฝ ์ค์น
1. JDK 11
2. Java FX
3. Eclipse 2022-09
โข
2023-06 ์ดํด๋ฆฝ์ค ์ต์ ๋ฒ์ ์์, fxml ํ์ผ ์์ฑ ์๋๋ ์ด์
ํ์ฅ๋๊ตฌ ์ค์น
โข
[Help] > [Eclipse Marketplace]
โข
โjavafxโ ๊ฒ์
โข
e(fx)clipse 3.8.0
โข
[install]
Java FX ํ๋ก์ ํธ ์์ฑ
โข
[New] > Java FX Project
โข
[Window] > [Preferences] > [Java > Build Path > User libraries]
โฆ
๋ค์ด๋ก๋ ๋ฐ์ Java FX(.jar) ๋ชจ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ผ ์ถ๊ฐ
โฆ
User lib name : Java FX
โข
ํด๋น ํ๋ก์ ํธ > [Build Path] > [lib] > [Add library] > [User library] > [Java FX]
์๋์์ฑ ์๋ ๋,
โข
[Window] > [Preferences]
โข
[Java] > [Editor] > [Content Assist] > [Advanced]
โฆ
Java Proposal ์ฒดํฌ
4. Scene Builder
์ดํด๋ฆฝ์ค์์ Scene Builder ์ฐ๊ฒฐ
โข
[Window] > [Preferences]
โฆ
Java FX
โฆ
Scene Builder.exe ๊ฒฝ๋ก ์ง์
์์์ฝ๋
// Main.java
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 stage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
stage.setScene(scene);
stage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Java
๋ณต์ฌ
// module-info.java
module JavaFX_Test {
requires javafx.controls;
requires javafx.fxml; // ์ถ๊ฐ
opens application to javafx.graphics, javafx.fxml;
}
Java
๋ณต์ฌ
Main.fxml ํ์ผ ์์ฑ
โข
[New] > [fxml]
Scene Builder ์คํ
1.
Main.fxml [์ฐํด๋ฆญ]
2.
Open with Scene Builder
a.
Preferences ์์ Scene Builder ์ฐ๊ฒฐํด์ผ ์คํ๋จ
// Main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="193.0" layoutY="70.0" text="์๋
ํ์ธ์">
<font>
<Font size="43.0" />
</font>
</Label>
</children>
</AnchorPane>
Java
๋ณต์ฌ