【发布时间】:2017-11-08 17:40:39
【问题描述】:
我从早上开始就想知道如何解决这个问题。我有登录应用程序。当用户等待登录时,我想使用 processindicator。我使用了第二个线程,但它不起作用
主加载器 fxml
主控制器
@FXML public StackPane MainStackPane;
public void initialize(URL arg0, ResourceBundle arg1) {
FXMLLoader loader = new FXMLLoader(this.getClass().getResource("/LoginForm/Login.fxml"));
Pane pane = null;
try {
pane = loader.load();
} catch (IOException e) {System.out.println(e.getMessage());}
LoginController login = loader.getController();
login.setMainController(this);
setScreen(pane, true);
}
public void setScreen(Pane pane, boolean clean){
MainStackPane.getChildren().addAll(pane);
}
登录表单:
private MainController mainController;
private void Zaloguj() throws IOException {
String cryptUser = null, cryptPass = null;
Test test = new Test(this.mainController);
test.start();
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
LoginSQL sql = new LoginSQL();`
Byte LoginResult = sql.SQLselect(cryptUser, cryptPass);
...}
课堂测试
public class test extends Service<Void>{
private MainController mainController;
public test(MainController mainController) {
this.mainController = mainController;
}
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
System.out.println("Service: START");
ProgressIndicator p = new ProgressIndicator();
Platform.runLater(new Runnable() {
@Override public void run() {
mainController.MainStackPane.getChildren().addAll(p);
}});
if (isCancelled()) {
mainController.MainStackPane.getChildren().remove(p);
}
return null;
};};}}
ProgressIndicator 仅在登录后出现在下一个窗口中。怎么办?
【问题讨论】: