我一直在寻找互联网,我找不到我的问题的答案,所以我会尝试自己做,并希望最好!JavaFX - FadeOut - >切换阶段
我有一个首要的东西,它提供了一个欢迎然后淡出,但是我想在那个淡出不见的时刻切换舞台!有没有人有这个答案?
下面的小代码,以获得更好的理解:
import java.util.Timer;
import java.util.TimerTask;
import javafx.animation.FadeTransition;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.util.Duration;
public class TextFileOPG extends Application {
private Stage switchStage;
@Override
public void start(Stage primaryStage) {
try {
switchStage = primaryStage;
GridPane root = new GridPane();
root.setAlignment(Pos.CENTER);
Text scenetitle = new Text("Welcome");
scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 40));
root.add(scenetitle, 3, 2);
FadeTransition ftOUT = new FadeTransition(Duration.millis(3000), root);
ftOUT.setFromValue(1.0);
ftOUT.setToValue(0.0);
ftOUT.play();
if(ftOUT.equals(Duration.millis(3000)))
{
loggedIn();
}
primaryStage.setTitle("Welcome");
Scene scene = new Scene(root,350,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public void loggedIn()
{
switchStage.setTitle("Try");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
Text thisIsSoCoolText = new Text("Welcome Again");
thisIsSoCoolText.setFont(Font.font("Tahoma", FontWeight.NORMAL, 40));
grid.add(thisIsSoCoolText, 3, 2);
Scene scene = new Scene(grid, 350, 400);
switchStage.setScene(scene);
switchStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
嗨,哥们。谢谢 !我试过你的解决方案,它工作得很好!很好学习一些TimeLine! –
欢迎您,如果您有任何其他问题,只需提交 – sazzy4o