Reputation: 11
hi am using JavaFx i want to create a simple window that will appear at first the application will go start then it will stay for short time then it will disappear automatically without any event then my main window will appear now can anyone help me in this idea
Upvotes: 1
Views: 837
Reputation: 583
package x;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class AutoHideExmpl extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
VBox v = new VBox();
TextField fiiled = new TextField("asdasdf");
TextField d = new TextField("asdfasdf");
TextField gd = new TextField("asdf");
TextField da = new TextField("asdf");
TextField cd = new TextField("asdf");
v.getChildren().addAll(fiiled, d, gd, da, cd);
v.setMinSize(500, 500);
Scene c = new Scene(v);
primaryStage.setScene(c);
primaryStage.show();
Stage s1 = new Stage();
VBox v1 = new VBox();
TextField fiiled1 = new TextField("asdasdf");
TextField d1 = new TextField("asdfasdf");
TextField gd1 = new TextField("asdf");
TextField da1 = new TextField("asdf");
TextField cd1 = new TextField("asdf");
v1.getChildren().addAll(fiiled1, d1, gd1, da1, cd1);
v1.setMinSize(300, 300);
Scene c1 = new Scene(v1);
s1.setScene(c1);
s1.show();
Task t = new Task<Void>() {
@Override
protected Void call() throws Exception {
Thread.sleep(60000);
Platform.runLater(() -> {
s1.close();
});
System.out.println("hidding");
return null;
}
};
Thread ts = new Thread(t);
ts.start();
}
}
you can user this too
Thread ts = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(60000);
Platform.runLater(() -> {
s1.close();
});
System.out.println("hidding");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
ts.start();
i hope this will help you if any ? write comment
Upvotes: 1