add label for current playnig
This commit is contained in:
@@ -17,6 +17,7 @@ public class MusicController {
|
||||
|
||||
@FXML Button playButton;
|
||||
private boolean isPlaying = false;
|
||||
@FXML private Label currentplaying;
|
||||
@FXML private ListView<Song> musicListView;
|
||||
private ObservableList<Song> musicList = FXCollections.observableArrayList();
|
||||
private ObservableList<Song> playList = FXCollections.observableArrayList();
|
||||
@@ -38,13 +39,16 @@ public class MusicController {
|
||||
|
||||
@FXML
|
||||
public void handlePlayAction() {
|
||||
if (isPlaying) {
|
||||
isPlaying = false;
|
||||
playButton.setText("play");
|
||||
}
|
||||
else {
|
||||
isPlaying = true;
|
||||
playButton.setText("pause");
|
||||
if (musicListView.getSelectionModel().getSelectedItem() != null) {
|
||||
if (isPlaying) {
|
||||
isPlaying = false;
|
||||
playButton.setText("play");
|
||||
currentplaying.setText("");
|
||||
} else {
|
||||
isPlaying = true;
|
||||
playButton.setText("playing");
|
||||
currentplaying.setText("Now playing: " + musicListView.getSelectionModel().getSelectedItem().getSongName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<BorderPane
|
||||
xmlns:fx="http//javafx.com/fxml"
|
||||
fx:controller="sbu.javafx.MusicController">
|
||||
@@ -15,14 +17,17 @@
|
||||
</center>
|
||||
|
||||
<bottom>
|
||||
<HBox spacing="10" alignment="CENTER">
|
||||
<Button text="Previous" onAction="#handlePrevious"/>
|
||||
<Button fx:id="playButton" text="Play" onAction="#handlePlayAction"/>
|
||||
<Button text="Next" onAction="#handlenext"/>
|
||||
<Button text="add to playlist" onAction="#addToPlaylist"/>
|
||||
<Button text="show playList" onAction="#openPlaylistWindow"/>
|
||||
<Button text="show all songs" onAction="#openAllSongs"/>
|
||||
</HBox>
|
||||
<VBox spacing="10" alignment="CENTER">
|
||||
<Label fx:id="currentplaying" text=" "/>
|
||||
<HBox spacing="10" alignment="CENTER">
|
||||
<Button text="Previous" onAction="#handlePrevious"/>
|
||||
<Button fx:id="playButton" text="Play" onAction="#handlePlayAction"/>
|
||||
<Button text="Next" onAction="#handlenext"/>
|
||||
<Button text="add to playlist" onAction="#addToPlaylist"/>
|
||||
<Button text="show playList" onAction="#openPlaylistWindow"/>
|
||||
<Button text="show all songs" onAction="#openAllSongs"/>
|
||||
</HBox>
|
||||
</VBox>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user