forked from AdvancedProgramming1404/HW-07-JavaFX
implement music player + JavaFx UI
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package sbu.javafx;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PlaylistController
|
||||
{
|
||||
|
||||
@FXML
|
||||
private ListView<String> playlistListView;
|
||||
|
||||
private ArrayList<Song> playlist = new ArrayList<>();
|
||||
|
||||
public void setPlaylist(ArrayList<Song> playlist)
|
||||
{
|
||||
this.playlist = playlist;
|
||||
refreshPlaylist();
|
||||
}
|
||||
|
||||
private void refreshPlaylist()
|
||||
{
|
||||
playlistListView.getItems().clear();
|
||||
|
||||
if (playlist.isEmpty())
|
||||
playlistListView.getItems().add("Playlist is empty.");
|
||||
else
|
||||
for (Song song : playlist)
|
||||
playlistListView.getItems().add(song.toString());
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void goBack()
|
||||
{
|
||||
try
|
||||
{
|
||||
FXMLLoader loader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
|
||||
Scene scene = new Scene(loader.load(), 1280, 900);
|
||||
|
||||
Stage stage = (Stage) playlistListView.getScene().getWindow();
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("Music Player");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR, "Failed to return to main screen.", ButtonType.OK);
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user