我正在嘗試創建一個加載窗口。但是我有MySQL驅動程序的問題。這是問題,當我添加一些對象,在我的情況下GIF(但我也嘗試矩形)到我的場景(到組),然后它連接到數據庫,舞臺不會顯示任何對象,直到數據庫連接完成。我嘗試了一些我在互聯網上找到的例子,但沒有任何效果。所以我在這里找到了幫助。這是我嘗試的代碼。private void afterClick() { showLoading(); username = name.getText(); password = passField.getText(); if ((username.length() == 0) && (password.length() == 0)) { Alert.printInformation("Nezadali jste p?ihla?ovací údaje."); } else if (username.length() == 0) { Alert.printInformation("Nezadali jste login."); } else if (password.length() == 0) { Alert.printInformation("Nezadali jste heslo."); } else { DBConnection connection = new DBConnection(); if(connection.connect()){ if (check.isSelected()) { FileStream.writeToFile("Account.txt", LoginMenu.username + ";" + LoginMenu.password, false); } else { FileStream.writeToFile("Account.txt", "empty", false); } App.showScene(MenuName.MainMenu); } }}void showLoading(){ ImageView loading = new ImageView(new Image("file:Wallpapers/loading.gif")); loading.setX(App.width -100); loading.setY(App.height - 100); loading.setFitWidth(60); loading.setFitHeight(60); Stage stage = new Stage(); Group group = new Group(); Scene scene1 = new Scene(group); group.getChildren().add(loading); stage.setScene(scene1); scene1.setFill(Color.TRANSPARENT); stage.initStyle(StageStyle.TRANSPARENT); stage.show();}
1 回答

慕碼人2483693
TA貢獻1860條經驗 獲得超9個贊
它非常簡單!您可以使用重寫初始化方法進行一些“pre”移動。
class YourControllerClass implements Initializable{ @Override public void initialize(URL location, ResourceBundle resources) { //Do stuff } }
你還可以像這樣在初始化方法 new Thread 中運行,以防止阻塞你的應用。
new Thread(() -> { //Your stuff }).run();
添加回答
舉報
0/150
提交
取消