Search

JavaFX

JavaFX

Java ν”Œλž«νΌμ—μ„œ ν’λΆ€ν•œ κ·Έλž˜ν”½ μ‚¬μš©μž μΈν„°νŽ˜μ΄μŠ€(GUI) μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ κ°œλ°œν•˜κΈ° μœ„ν•œ μ˜€ν”ˆ μ†ŒμŠ€ μœ„μ ― 개발 도ꡬ

JavaFX ν•΅μ‹¬κ°œλ…

β€’
Stage
β€’
Scene
β€’
Node
β€’
Control
β€’
Layout
β€’
Event
β€’
CSS
β€’
FXML

Stage

ν”„λ‘œκ·Έλž¨μ˜Β μ΅œμƒμœ„ μœˆλ„μš°

κ΅¬μ„±μš”μ†Œ

β€’
메뉴
β€’
도ꡬλͺ¨μŒ
β€’
μƒνƒœ ν‘œμ‹œμ€„
β€’
μ—¬λŸ¬ 개의 Scene
ν•˜λ‚˜μ˜ μΈμŠ€ν„΄μŠ€λ§Œ μ‘΄μž¬ν•˜κ³ , ν”„λ‘œκ·Έλž¨μ΄ 싀행될 λ•Œ, μƒμ„±λ©λ‹ˆλ‹€.

Scene

Stage μœ„μ— ν‘œμ‹œλ˜λŠ” 컨텐츠 μ˜μ—­(ν™”λ©΄)

κ΅¬μ„±μš”μ†Œ

β€’
컨트둀
β€’
λ ˆμ΄μ•„μ›ƒ
β€’
κ·Έλž˜ν”½
UI μš”μ†Œλ“€μ΄ 배치될 수 μžˆλŠ” μ˜μ—­μž…λ‹ˆλ‹€.

Node

JavaFX μ—μ„œ λ‚˜νƒ€λ‚΄λŠ” 기본적인 UI μš”μ†Œ

λ…Έλ“œμ˜ λΆ„λ₯˜

β€’
컨트둀
β€’
λ ˆμ΄μ•„μ›ƒ
β€’
ν…μŠ€νŠΈ
β€’
이미지
β€’
λ„ν˜•

λ…Έλ“œμ˜ νŠΉμ§•

β€’
μœ„μΉ˜, 크기, μŠ€νƒ€μΌ 등을 μ§€μ •ν•˜μ—¬ UI μš”μ†Œλ₯Ό ν‘œν˜„ν•  수 μžˆλ‹€.
β€’
Scene μœ„μ— ν‘œμ‹œν•  λ²„νŠΌ, 이미지 λ“±μ˜ 역할을 ν•œλ‹€.

Control

λ©”μ†Œλ“œμ™€ μ—°κ²°λœ λ…Έλ“œλ‘œμ¨, μ‚¬μš©μžμ™€ μƒν˜Έ μž‘μš©μ„ ν•˜λŠ” μš”μ†Œ
β€’
이벀트 처리 κΈ°λŠ₯을 μ œκ³΅ν•˜κΈ° μœ„ν•΄μ„œ μ‚¬μš©λœλ‹€.

μ’…λ₯˜

β€’
λ²„νŠΌ
β€’
ν…μŠ€νŠΈ ν•„λ“œ
β€’
μ²΄ν¬λ°•μŠ€
β€’
콀보 λ°•μŠ€

Layout

λ…Έλ“œλ₯Ό Scene 에 λ°°μΉ˜ν•˜λŠ” 방법을 μ •μ˜ν•˜λŠ” μ˜μ—­

μ’…λ₯˜

β€’
VBox
β€’
HBox
β€’
GridPane
β€’
AnchorPane

Event

μ‚¬μš©μžμ˜ μƒν˜Έ μž‘μš©κ³Ό κ΄€λ ¨λœ ν–‰μœ„

μ’…λ₯˜

β€’
클릭
β€’
ν‚€ μž…λ ₯
β€’
λ“œλž˜κ·Έ μ•€ λ“œλ‘­
컨트둀 μš”μ†Œμ— νŠΉμ • 이벀트λ₯Ό μ§€μ •ν•˜κ³ , ν•΄λ‹Ή μ΄λ²€νŠΈμ™€ λ©”μ†Œλ“œλ₯Ό μ—°κ²°ν•˜μ—¬ μ‚¬μš©μžμ˜ μƒν˜Έ μž‘μš©μ— λŒ€ν•œ κΈ°λŠ₯을 μ²˜λ¦¬ν•©λ‹ˆλ‹€.

CSS

μŠ€νƒ€μΌ μ‹œνŠΈ. ν™”λ©΄ μš”μ†Œμ— λŒ€ν•œ μŠ€νƒ€μΌ μ§€μ •ν•˜λŠ” 파일
β€’
κΈ€κΌ΄, 색상, 이미지, λ°°κ²½ 등을 μ„€μ •ν•˜μ—¬ ν”„λ‘œκ·Έλž¨μ˜ λ””μžμΈμ„ μ •μ˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

FXML

JavaFX μ—μ„œ Scene 을 μ •μ˜ν•˜λŠ” XML 기반 μ–Έμ–΄
SceneBuilder 도ꡬλ₯Ό μ΄μš©ν•˜μ—¬ λ””μžμΈ νŽΈμ§‘μ„ ν•  수 μžˆλ‹€.
SceneBuilder 둜 λ“œλž˜κ·Έ&λ“œλž ν•˜μ—¬ UI λ””μžμΈμ„ ν•˜λ©΄, μ½”λ“œκ°€ μžλ™ μ™„μ„±λœλ‹€.
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Button?> <?import javafx.scene.layout.AnchorPane?> <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="484.0" prefWidth="510.0" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1"> <children> <Button layoutX="260.0" layoutY="239.0" mnemonicParsing="false" text="Button" /> <Button layoutX="149.0" layoutY="239.0" mnemonicParsing="false" text="Button" /> <Button layoutX="206.0" layoutY="239.0" mnemonicParsing="false" text="Button" /> </children> </AnchorPane>
XML
볡사