์ปจํธ๋กค๋ฌ ์๋ช ์ฃผ๊ธฐ
JavaFX ์ปจํธ๋กค๋ฌ๋ FXMLLoader.load() ์ ์๋ ์์ฑ๋๊ณ , FXML ์ฃผ์
ํ initialize()๊ฐ ํธ์ถ๋๋ค. ์ผ๋ฐ ๋ฉ์๋ ํ, UI ๋ณ๊ฒฝ์ Platform.runLater()๋ก ์์ ํ๊ฒ ์ฒ๋ฆฌ๋๋ค.
JavaFX ์ปจํธ๋กค๋ฌ ์๋ช
์ฃผ๊ธฐ
sequenceDiagram
participant StageManager
participant Controller as Controller
participant FXThread as JavaFX Application Thread
StageManager->>Controller: new Controller() ์์ฑ<br> (FXMLLoader.load())
FXThread->>Controller: initialize() ํธ์ถ
note right of Controller: FXML ๋ก๋ ํ ์๋ ํธ์ถ
StageManager->>Controller: receiveData(data) ํธ์ถ
note right of Controller: StageManager๊ฐ ๋ฐ์ดํฐ ์ ๋ฌ
Controller->>FXThread: Platform.runLater(() -> {...}) ๋ฑ๋ก
note right of FXThread: UI ์
๋ฐ์ดํธ ์ฝ๋ ์์ฝ
FXThread-->>Controller: runLater ๋ด๋ถ ์ฝ๋ ์คํ
note right of Controller: UI ์ค๋ ๋์์ ์์ ํ๊ฒ ์คํ๋จ
Mermaid
๋ณต์ฌ
๋จ๊ณ๋ณ ์ค๋ช
โ FXMLLoader.load() ์คํ
โข
StageManager์์ FXMLLoader.load()๋ฅผ ํธ์ถํ๋ฉด,
โฆ
FXML ํ์ผ์ ํด์ํ๋ฉด์ <fx:controller>๋ก ์ง์ ๋ ํด๋์ค(Controller)์ ์ธ์คํด์ค๋ฅผ ์๋ ์์ฑํฉ๋๋ค.
โ ์ฆ, new Controller() ๊ฐ ๋ด๋ถ์ ์ผ๋ก ์คํ๋จ.
โข
์์ฑ ์งํ, FXML ๋ด์ UI ์ปดํฌ๋ํธ(@FXML TextField input ๋ฑ)๊ฐ ์๋์ผ๋ก ์ฃผ์
๋ฉ๋๋ค.
โก initialize() ์๋ ํธ์ถ
โข
๋ชจ๋ FXML ์์๊ฐ ์ฃผ์
๋ ํ,
์ปจํธ๋กค๋ฌ์ @FXML initialize() ๋ฉ์๋๊ฐ ์๋ ํธ์ถ๋ฉ๋๋ค.
โข
์ด๊ธฐํ ๋ก์ง(UI ๊ธฐ๋ณธ ์ค์ , ๋ฆฌ์ค๋ ๋ฑ๋ก ๋ฑ)์ ์ฌ๊ธฐ์ ์์ฑํฉ๋๋ค.
โข
์์ง StageManager์์ ๋ฐ์ดํฐ ์ ๋ฌ ์ ์ด๋ผ,
์ธ๋ถ ๊ฐ(receiveData)์ ์์ง null์ผ ์ ์์ต๋๋ค.
โข StageManager.show(fxml, data) โ receiveData() ํธ์ถ
โข
StageManager๊ฐ ํ๋ฉด ์ ํ์ ์๋ฃํ ๋ค,
์ ์ปจํธ๋กค๋ฌ๊ฐ DataReceiver๋ฅผ ๊ตฌํํ๊ณ ์๋ค๋ฉด receiveData(data)๋ฅผ ํธ์ถํฉ๋๋ค.
โข
์ด ๋จ๊ณ์์ ์ธ๋ถ ๋ฐ์ดํฐ(์: ๋ก๊ทธ์ธ ์ ๋ณด, ์ฌ์ฉ์ ์ด๋ฆ ๋ฑ)๋ฅผ ์ ๋ฌ๋ฐ์ต๋๋ค.
โฃ Platform.runLater() ํธ์ถ
โข
receiveData() ์์์ UI ์์๋ฅผ ๋ณ๊ฒฝํ๋ ค๋ฉด
JavaFX UI Thread์์ ์์ ํ๊ฒ ์คํ๋์ด์ผ ํฉ๋๋ค.
โข
Platform.runLater(() -> {...}) ๋ฅผ ์ฌ์ฉํ๋ฉด
์ ๋ฌ๋ ์ฝ๋ ๋ธ๋ก์ด JavaFX Application Thread ํ์ ๋ฑ๋ก๋์ด,
๋ค์ UI ํ๋ ์ ์์ ์ ์์ ํ๊ฒ ์คํ๋ฉ๋๋ค.
โค runLater ๋ด๋ถ ์ฝ๋ ์คํ
โข
JavaFX Application Thread๊ฐ ๋ฑ๋ก๋ ์์
์ ์คํํฉ๋๋ค.
โข
์ด๋ TextField.setText() ๋ฑ UI ๋ณ๊ฒฝ์ด ๋ฐ์ํด๋ ์์ ํฉ๋๋ค.
โข
ํ๋ฉด์ด ์ต์ข
๊ฐฑ์ ๋ฉ๋๋ค.
ํต์ฌ ์์ฝ
์์ | ๋จ๊ณ | ์คํ ์ค๋ ๋ | ์ค๋ช
|
1 | Controller ์์ฑ (FXMLLoader.load()) | JavaFX Application Thread | FXML ๋ก๋ ์ ์๋ ์์ฑ |
2 | initialize() | JavaFX Application Thread | UI ๊ตฌ์ฑ์์ ์ด๊ธฐํ |
3 | receiveData() | JavaFX Application Thread | StageManager์์ ๋ฐ์ดํฐ ์ ๋ฌ |
4 | Platform.runLater() ๋ฑ๋ก | JavaFX Application Thread | UI ๋ณ๊ฒฝ ์ฝ๋ ์์ฝ |
5 | runLater ์คํ | JavaFX Application Thread | UI ์์ ํ๊ฒ ๊ฐฑ์ |




