From 26e0b071d013b6df567dee6f0d67bb75c07e93b6 Mon Sep 17 00:00:00 2001 From: Reza Date: Tue, 26 May 2026 14:00:50 +0330 Subject: [PATCH] complete --- .idea/vcs.xml | 6 ++ src/main/java/sbu/javafx/Launcher.java | 3 +- src/main/java/sbu/javafx/MusicApp.java | 3 +- src/main/java/sbu/javafx/MusicController.java | 77 ++++++++++++++++--- src/main/resources/sbu/javafx/App-view.fxml | 42 +++++++++- src/main/resources/sbu/javafx/dark.css | 51 ++++++++++++ src/main/resources/sbu/javafx/light.css | 47 +++++++++++ 7 files changed, 212 insertions(+), 17 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 src/main/resources/sbu/javafx/dark.css create mode 100644 src/main/resources/sbu/javafx/light.css diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/sbu/javafx/Launcher.java b/src/main/java/sbu/javafx/Launcher.java index c288d10..ab853fa 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -4,5 +4,6 @@ import javafx.application.Application; 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/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java index a50badc..579d067 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -4,6 +4,7 @@ import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; +import javafx.scene.image.Image; import java.io.IOException; @@ -16,7 +17,7 @@ public class MusicApp extends Application { Scene scene = new Scene(fxmlLoader.load()); stage.setTitle("Music Player"); stage.setScene(scene); - //TODO: add icon to the stage + scene.getStylesheets().add(getClass().getResource("dark.css").toExternalForm()); stage.show(); } diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..fe07c12 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -3,29 +3,82 @@ package sbu.javafx; import javafx.fxml.FXML; import javafx.event.ActionEvent; import javafx.scene.control.Label; +import javafx.scene.control.Button; +import javafx.scene.control.ListView; +import javafx.scene.Scene; import javafx.scene.input.MouseEvent; 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. - - //TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. + @FXML + private Label nowPlayingLabel; @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. + private Button playBtn1, playBtn2, playBtn3; + private final ArrayList playlist = new ArrayList<>(); + private boolean isDark = true; + + @FXML + public void toggleTheme() { + Scene scene = playBtn1.getScene(); + scene.getStylesheets().clear(); + if (isDark) { + scene.getStylesheets().add(getClass().getResource("light.css").toExternalForm()); + } else { + scene.getStylesheets().add(getClass().getResource("dark.css").toExternalForm()); + } + isDark = !isDark; } + private void resetPlayButtons() { + playBtn1.setText("Play"); + playBtn1.setStyle(null); + playBtn2.setText("Play"); + playBtn2.setStyle(null); + playBtn3.setText("Play"); + playBtn3.setStyle(null); + } + @FXML + public void handlePlayAction(ActionEvent event) { + resetPlayButtons(); + Button clicked = (Button) event.getSource(); + clicked.setText("Playing"); + clicked.setStyle("-fx-background-color: #4CAF50; -fx-text-fill: white;"); - //TODO: Logic to add a specific song to the user's playlist. - + if (clicked == playBtn1) { + nowPlayingLabel.setText("Now Playing: Blinding Lights - The Weeknd"); + } else if (clicked == playBtn2) { + nowPlayingLabel.setText("Now Playing: Bohemian Rhapsody - Queen"); + } else if (clicked == playBtn3) { + nowPlayingLabel.setText("Now Playing: Hotel California - Eagles"); + } + } public void addToPlaylist(String songName) { - //Add the song to a list or update a ListView. + playlist.add(songName); + System.out.println("Added to playlist: " + songName); } - - // TODO:This method should open a new window or change the current scene to display the "Playlist" page. - + @FXML public void openPlaylistWindow() { - //Create a new stage and show the playlist UI. + Stage playlistStage = new Stage(); + playlistStage.setTitle("My Playlist"); + + ListView listView = new ListView<>(); + listView.getItems().addAll(playlist); + + VBox root = new VBox(listView); + Scene scene = new Scene(root, 300, 400); + playlistStage.setScene(scene); + playlistStage.show(); } + @FXML + public void handleAdd1() { addToPlaylist("Blinding Lights - The Weeknd"); } + + @FXML + public void handleAdd2() { addToPlaylist("Bohemian Rhapsody - Queen"); } + + @FXML + public void handleAdd3() { addToPlaylist("Hotel California - Eagles"); } + } diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 306c8d3..e2bfef1 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,44 @@ + + + + - - - + + + +