Search

Java FX ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ค์น˜

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
๋ณต์‚ฌ

๊ฒฐ๊ณผ ํ™”๋ฉด