播放多个视频JavaFx

时间:2013-11-08 15:15:05

标签: java javafx

我是JavaFx的新手,我有一个带有3个ToggleButtons的vbox,当我点击一个按钮时,一个视频将开始播放另一个有3列的布局,这样我就可以通过点击3 ToggleButtons在该布局上播放3个视频。我没有找到任何教程帮助。谁能建议怎么做? 这是我的3个按钮代码

   private static Scene createScene() {
    Group root = new Group();
    Scene scene = new Scene(root);

    // Création du layout pour les vidéos ainsi que du media builder pour
    // construire les vidéos
    VBox gridpane = new VBox(0.4);

    gridpane.setMaxWidth(Double.MAX_VALUE);
    gridpane.setStyle("-fx-border-style: solid;"
                + "-fx-border-width: 1;"
                + "-fx-border-color: black");
    Image progress = new Image(mediaplayer.class.getResourceAsStream("/cameras_images/im1.jpg"));
    Image im2 = new Image(mediaplayer.class.getResourceAsStream("/cameras_images/im2.jpg"));
    Image im3 = new Image(mediaplayer.class.getResourceAsStream("/cameras_images/im3.jpg"));


    ToggleButton bouton1 = new ToggleButton(" 1      ",new ImageView(progress));
      bouton1.setContentDisplay(ContentDisplay.RIGHT);
    ToggleButton bouton2 = new ToggleButton(" 2                 ",new ImageView(im2));
    bouton2.setContentDisplay(ContentDisplay.RIGHT);
    bouton2.setMaxWidth(Double.MAX_VALUE);


    ToggleButton bouton3 = new ToggleButton(" 3                                                           ",new ImageView(im3));
    bouton3.setContentDisplay(ContentDisplay.RIGHT);

    bouton3.setMaxWidth(Double.MAX_VALUE);

     gridpane.getChildren().add(bouton1); 
     gridpane.getChildren().add(bouton2);  
     gridpane.getChildren().add(bouton3); 


    root.getChildren().add(gridpane);


    return (scene);
}

1 个答案:

答案 0 :(得分:1)

现在按钮什么都不做。您需要向按钮添加侦听器,以便在用户切换按钮时触发操作。像这样:

bouton1.setOnAction(new EventHandler<ActionEvent>() {
    @Override public void handle(ActionEvent e) {

        //if button is selected, start video
        //if button is deselected, stop video
    }
});