From 58536d2bcef86a931f1269fa4fcc012208850408 Mon Sep 17 00:00:00 2001 From: ShayanEdalatjoo Date: Fri, 17 Jul 2026 01:10:10 +0330 Subject: [PATCH] finishing controller and fxml hotfix --- src/main/java/sbu/javafx/MusicController.java | 68 +++++++++++++++---- src/main/resources/sbu/javafx/App-view.fxml | 30 +++++--- 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..c743761 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -1,31 +1,75 @@ package sbu.javafx; -import javafx.fxml.FXML; +import javafx.collections.FXCollections; import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.Scene; +import javafx.scene.control.Button; import javafx.scene.control.Label; -import javafx.scene.input.MouseEvent; +import javafx.scene.control.ListView; import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +import java.util.ArrayList; public class MusicController { - // TODO: Define your UI components using the @FXML annotation. + @FXML + private Label nowPlayingLabel; - //TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. + private final ArrayList playlist = new ArrayList<>(); @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. - } + public void handlePlayAction(ActionEvent event) { + Button button = (Button) event.getSource(); + String songName = ""; + switch (button.getId()) { + case "play1": + songName = "Blinding Lights"; + break; + case "play2": + songName = "Shape of You"; + break; + case "play3": + songName = "Believer"; + break; + } - //TODO: Logic to add a specific song to the user's playlist. + nowPlayingLabel.setText("Now Playing: " + songName); + } public void addToPlaylist(String songName) { - //Add the song to a list or update a ListView. + playlist.add(songName); } - // TODO:This method should open a new window or change the current scene to display the "Playlist" page. + @FXML + public void addSong1() { + addToPlaylist("Blinding Lights"); + } + @FXML + public void addSong2() { + addToPlaylist("Shape of You"); + } + + @FXML + public void addSong3() { + addToPlaylist("Believer"); + } + + @FXML public void openPlaylistWindow() { - //Create a new stage and show the playlist UI. + + Stage stage = new Stage(); + + ListView listView = new ListView<>(); + listView.setItems(FXCollections.observableArrayList(playlist)); + + VBox root = new VBox(10); + root.getChildren().addAll(new Label("Playlist"), listView); + + stage.setScene(new Scene(root, 300, 250)); + stage.setTitle("Playlist"); + stage.show(); } -} +} \ No newline at end of file diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 3244d8c..28598eb 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -12,28 +12,38 @@ spacing="10">