我正在尝试使用javafx创建游戏菜单。我现在有可以使用的首页。我有几个项目应该引导我进入下一个场景。
我使用:
private List<Pair<String, Runnable>> menuData = Arrays.asList(
new Pair<String, Runnable>("Un Joueur", OptionMenu::),
new Pair<String, Runnable>("Multijoueuer", () -> {}),
new Pair<String, Runnable>("Options du jeu", () -> {}),
new Pair<String, Runnable>("Quitter",Platform::exit)
);
创建我的商品,然后Platform ::退出所有内容。
问题是:我如何创建像OptionMenu :: something 这样的Runnable,使我进入扩展应用程序的下一页。我希望它与之接近:
public abstract static class OptionMenu extends Application implements Runnable{
///////// définition de la taille du menu ///////////
private static final int WIDTH = 1324;
private static final int HEIGHT = 604;
/////////////////////////////////////////////////////
//////// création des differents clicables //////////
private List<Pair<String, Runnable>> menuData = Arrays.asList(
new Pair<String, Runnable>("Un Joueur", () -> {}),
new Pair<String, Runnable>("Multijoueuer", () -> {}),
new Pair<String, Runnable>("Options du jeu", () -> {}),
new Pair<String, Runnable>("Quitter",Platform::exit)
);
//////////////////////////////////////////////////////
private Pane root = new Pane();
private VBox menuBox = new VBox(-5);
private void addBackground(){
ImageView imageView = new ImageView(new Image(getClass().getResource("MenuImages/bkground.jpg").toExternalForm()));
imageView.setFitWidth(WIDTH);
imageView.setFitHeight(HEIGHT);
root.getChildren().add(imageView);
}
private void addTitle() {
BomberBallTitle title = new BomberBallTitle("Options du jeu");
title.setTranslateX(WIDTH / 2 - title.getTitleWidth() / 2);
title.setTranslateY(HEIGHT / 3);
root.getChildren().add(title);
}
private void addMenu(double x, double y) {
menuBox.setTranslateX(x);
menuBox.setTranslateY(y);
menuData.forEach(data -> {
BomberBallMenuItem item = new BomberBallMenuItem(data.getKey());
item.setOnAction(data.getValue());
item.setTranslateX(-300);
Rectangle clip = new Rectangle(300, 30);
clip.translateXProperty().bind(item.translateXProperty().negate());
item.setClip(clip);
menuBox.getChildren().addAll(item);
});
root.getChildren().add(menuBox);
}
private Parent createContent() {
addBackground();
addTitle();
double lineX = WIDTH / 2 - 100;
double lineY = HEIGHT / 3 + 50;
addMenu(lineX + 5, lineY + 5);
return root;
}
public void run() {
launch();
}
@Override
public void start(Stage primaryStage) throws Exception{
Scene scene = new Scene(createContent());
primaryStage.setTitle("BomberBall Menu");
primaryStage.setScene(scene);
primaryStage.show();
}