implement music player + JavaFx UI

This commit is contained in:
amirM.t
2026-05-29 21:17:09 +03:30
parent fa5f8ab267
commit 3d6c5f90ca
7 changed files with 500 additions and 27 deletions
@@ -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();
}
}
}