gpt4 book ai didi

Javafx onMouseclicked 上

转载 作者:行者123 更新时间:2023-12-02 03:13:21 33 4
gpt4 key购买 nike

我有一个设置场景和舞台的主类

public class MediaPlayer extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Main-UI.fxml"));
stage.setTitle("Media Player");
stage.setScene(new Scene(root));
stage.show();
}
}

我还有一个 Controller 类,我在其中实现了大部分功能等。由于某种原因,我的 setOnMouseClicked 似乎不起作用。这是因为它不是调用 stage.show() 的同一个文件

下面是鼠标事件不起作用的函数示例。

private void setMediaViews(){
String path = "E:" + File.separator + "Videos" + File.separator + "UFC.205.PPV.Alvarez.vs.McGregor.HDTV.x264-Ebi.mp4";

media = new Media(new File(path).toURI().toString());
player = new MediaPlayer(media);
view = new MediaView(player);
VBox vbox = new VBox();
Slider slider = new Slider();
vbox.getChildren().add(slider);

videoMediaCont.setCenter(view);
videoMediaCont.setBottom(vbox);

player.play();

player.setOnReady(new Runnable() {
@Override
public void run() {
int w = player.getMedia().getWidth();
int h = player.getMedia().getHeight();


view.setFitWidth(900);
vbox.setAlignment(Pos.CENTER);
vbox.setMinHeight(50);

slider.setMaxSize(900,50);
slider.setMin(0.0);
slider.setValue(0.0);
slider.setMax(player.getTotalDuration().toSeconds());
slider.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
player.seek(Duration.seconds(slider.getValue()));
}

});

}
});

player.currentTimeProperty().addListener(new ChangeListener<Duration>() {
@Override
public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration current) {
slider.setValue(current.toSeconds());
}
});


}

任何帮助都会非常感谢。

最佳答案

我发现您尝试更改 slider 的值,如 docs 中所述。将您的“OnMouseClicked”事件替换为:

slider.valueProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> ov,
Number old_val, Number new_val) {

player.seek(Duration.seconds((double) new_val);

}});

关于Javafx onMouseclicked 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40729726/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com