我的方法不是抽象的,不能覆盖另一个方法

时间:2017-04-27 09:37:58

标签: java javafx fxml

我一直在尝试创建一个音乐播放器,其中一部分需要听一个时间滑块。所以我添加了时间幻灯片,这是我得到的错误:

enter image description here

我一直试图了解你如何修复这个错误以及整个覆盖的整个业务。

有人能指出我如何解决这个错误吗?

我的代码:

public class graphicalController implements Initializable 
{
    //GUI Decleration
    @FXML
    public Button centreButton;
    @FXML
    public Button backButton;
    @FXML
    public Button forwardButton;
    @FXML
    public ToggleButton muteToggle;
    @FXML
    public MenuItem loadFolder;
    @FXML
    public Text nameText;
    @FXML
    public Text albumText;
    @FXML
    public Text timeText;
    @FXML
    public Text artistText;
    @FXML
    public Slider timeSlider;
    @FXML
    public Slider volumeSlider;

    //Controller Decleration
    String absolutePath;
    SongQueue q = new SongQueue();
    MediaPlayer player;
    Status status;
    boolean isPlaying = false;
    boolean isMuted = false;
    boolean isPaused = false;
    private Duration duration;

    /**
     * The constructor. The constructor is called before the initialize()
     * method.
     * 
     * Anything in regards to CSS styling with FXML MUST be done within the initialize method.
     */

    public graphicalController() {

    }

    /**
     * Initializes the controller class. This method is automatically called
     * after the fxml file has been loaded.
     */

    @FXML
    public void initialize(URL location, ResourceBundle resources)
    {

        centreButton.setStyle("-fx-background-image: url('/Resources/Play_Button.png')");
        centreButton.setText("");

        backButton.setStyle("-fx-background-image: url('/Resources/Back_Button.png')");
        backButton.setText("");

        forwardButton.setStyle("-fx-background-image: url('/Resources/Forward_Button.png')");
        forwardButton.setText("");

        muteToggle.setStyle("-fx-background-image: url('/Resources/ToggleSound_Button.png')");
        muteToggle.setText("");

        nameText.setText("");
        albumText.setText("");
        artistText.setText("");

        volumeSlider.valueProperty().addListener(new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue<? extends Number> observable,
                Number oldValue, Number newValue) {
                    double sliderValue = newValue.intValue();
                    handleVolumeSlider(sliderValue);
                }
            });

        timeSlider.valueProperty().addListener(new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue<? extends Number> observable,
                Number oldValue, Number newValue) {

                    //outputTextArea.appendText("Slider Value Changed (newValue: " + newValue.intValue() + ")\n");
                }
            });

        timeSlider.valueProperty().addListener(new InvalidationListener() {
                public void invalidated(Observable ov) {
                    if (timeSlider.isValueChanging()) {
                        // multiply duration by percentage calculated by slider position
                        if(duration!=null) {
                            player.seek(duration.multiply(timeSlider.getValue() / 100.0));
                        }
                        updateValues();
                    }
                }
            });

    }


    public void setSongText() {
        String file = q.peek().fileName;
        String songName = q.peek().songName;
        String albumName = q.peek().albumName;
        String artistName = q.peek().artistName;
        if (songName == "") {
            songName = "Song name not specified in metadata.";
        }
        else if (albumName == "")
        {
            albumName = " Album name not specified in metadata.";
        }
        else if (artistName == "")
        {
            artistName = "Artist name not specified in metadata.";
        }
        nameText.setText(songName);
        albumText.setText(albumName);
        artistText.setText(artistName);
    }
}

您将在initialize方法中找到我的问题。

1 个答案:

答案 0 :(得分:2)

您使用的是正确的Observable类型吗?它应该是javafx.beans.Observable类型。