我试图根据用户在前一个场景中选择的按钮在某个场景中显示不同的内容。我尝试过使用 public static void main(String[] args)
和计时器来让它工作,但我就是做不到。
如何让 contentSelect() 在场景打开时运行? 我知道这应该很简单,但我无法让它在我的一生中发挥作用。
package application;
import java.time.Duration;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
public class GrammarTestController {
private static int picSelect=0;
@FXML
private Label title;
@FXML
private Label info;
@FXML
private ImageView image;
//Will decide which type of content to display
private void contentSelect(){
}
}
最佳答案
实现可初始化
:
public class GrammarTestController implements Initializable{
private static int picSelect=0;
@FXML
private Label title;
@FXML
private Label info;
@FXML
private ImageView image;
//This method is called upon fxml load
public void initialize(URL location, ResourceBundle resources) {
contentSelect();
}
//Will decide which type of content to display
private void contentSelect(){
}
}
关于java - 如何在打开新场景时运行 JavaFX 中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42942505/