From 5cdd18ca5029ee3e353593cccb58be138ee59ef8 Mon Sep 17 00:00:00 2001 From: Faraz Ardeh Date: Wed, 24 Jun 2026 12:32:26 +0330 Subject: [PATCH] Music Player app,7th Home Work. --- .idea/vcs.xml | 7 ++ pom.xml | 7 +- src/main/java/sbu/javafx/Launcher.java | 5 +- src/main/java/sbu/javafx/MusicController.java | 70 ++++++++++++++--- src/main/resources/sbu/javafx/App-view.fxml | 77 ++++++++++++++++++- 5 files changed, 148 insertions(+), 18 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..8306744 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index e45147d..49168d5 100644 --- a/pom.xml +++ b/pom.xml @@ -45,8 +45,8 @@ maven-compiler-plugin 3.13.0 - 23 - 23 + 21 + 21 @@ -58,7 +58,8 @@ default-cli - sbu.javafx/sbu.javafx.MusicApp + + sbu.javafx.Launcher app app app diff --git a/src/main/java/sbu/javafx/Launcher.java b/src/main/java/sbu/javafx/Launcher.java index c288d10..bc852f6 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -2,7 +2,8 @@ package sbu.javafx; import javafx.application.Application; -public class Launcher{ +public class Launcher { public static void main(String[] args) { - // TODO: Launch the JavaFX application by calling Application.launch(Main.class) } + Application.launch(MusicApp.class, args); + } } diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..1be890b 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -1,31 +1,79 @@ package sbu.javafx; -import javafx.fxml.FXML; +import javafx.collections.FXCollections; import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +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. + @FXML private Button playBtn1; + @FXML private Button playBtn2; + @FXML private Button playBtn3; + + private final ArrayList playlist = new ArrayList<>(); + private Button currentlyPlayingBtn; + private Scene mainScene; @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. - } + public void handlePlayAction(ActionEvent event) { + Button clicked = (Button) event.getSource(); + String song = (String) clicked.getUserData(); - //TODO: Logic to add a specific song to the user's playlist. + // Visual feedback: reset previous button, mark new one + if (currentlyPlayingBtn != null) { + currentlyPlayingBtn.setText("Play"); + } + clicked.setText("Playing"); + currentlyPlayingBtn = clicked; + + nowPlayingLabel.setText("Now Playing: " + song); + } public void addToPlaylist(String songName) { - //Add the song to a list or update a ListView. + if (!playlist.contains(songName)) { + playlist.add(songName); + } } - // TODO:This method should open a new window or change the current scene to display the "Playlist" page. + @FXML + public void handleAddToPlaylist(ActionEvent event) { + Button clicked = (Button) event.getSource(); + String song = (String) clicked.getUserData(); + addToPlaylist(song); + } + @FXML public void openPlaylistWindow() { - //Create a new stage and show the playlist UI. + Stage stage = (Stage) nowPlayingLabel.getScene().getWindow(); + mainScene = stage.getScene(); + + Label title = new Label("Your Playlist"); + title.setStyle("-fx-font-size: 20; -fx-font-weight: bold;"); + + ListView listView = new ListView<>( + FXCollections.observableArrayList(playlist) + ); + listView.setPrefHeight(200); + + Button backButton = new Button("Back to Player"); + backButton.setOnAction(e -> stage.setScene(mainScene)); + + VBox layout = new VBox(15, title, listView, backButton); + layout.setPadding(new Insets(25)); + layout.setAlignment(Pos.CENTER); + + stage.setScene(new Scene(layout, 400, 350)); } } diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 306c8d3..e9e7a12 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,81 @@ - + + + + + + - + + + + +