任何帮助将不胜感激。
我正在尝试在预加载器完成其循环之后加载新的舞台或场景,但是在初始化任务并添加新的fxmlloader之后,我的代码似乎什么也没做。
我不知道还能尝试什么。
您可以看到以下代码:
class DoWork extends Task<Integer> {
@Overrideimport java.net.URL;
protected Integer call() throws Exception{
for(int i =2 ; i < 21 ; i++){
System.out.println(i * 5);
updateProgress(i * 5, 100);
Thread.sleep(300);
if(isCancelled()){
return i;
}
}
return 21;
}
@Override
public boolean cancel( boolean mayInterruptIfRunning){
updateMessage("cancelled!");
return super.cancel(mayInterruptIfRunning);
}
@Override
protected void updateProgress(double workDone, double max){
updateMessage("Loading..." + " " + workDone + "%");
super.updateProgress(workDone, max);
}
}
public class LoaderController implements Initializable {
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private Label status;
@FXML
private ProgressBar bar;
//@FXML
//private ProgressIndicator indicator;
@Override
public void initialize(URL location, ResourceBundle rb){
DoWork task = new DoWork();
bar.progressProperty().bind(task.progressProperty());
//indicator.progressProperty().bind(task.progressProperty());
status.textProperty().bind(task.messageProperty());
new Thread(task).start();
}
public void start(Stage stage) throws Exception {
stage.initStyle(StageStyle.TRANSPARENT);
Parent root =
FXMLLoader.load(getClass().getResource("./splash/sceneOne.fxml"));
//stage.setTitle("Welcome");
stage.setScene(new Scene(root, 337, 144));
stage.show();
}
如何解决此问题?