From 7e5c277dc44ab46d9f4c5892291e7182763b984b Mon Sep 17 00:00:00 2001 From: Hesam Ghazi Date: Fri, 26 Jun 2026 02:11:27 +0330 Subject: [PATCH] HW-07-JavaFX is complete --- .idea/.name | 1 + .idea/inspectionProfiles/Project_Default.xml | 8 ++ .idea/misc.xml | 2 +- .idea/vcs.xml | 6 ++ src/main/java/sbu/javafx/Launcher.java | 11 ++- src/main/java/sbu/javafx/MusicApp.java | 1 - src/main/java/sbu/javafx/MusicController.java | 96 ++++++++++++++++--- .../java/sbu/javafx/PlaylistController.java | 33 +++++++ src/main/resources/sbu/javafx/App-view.fxml | 85 +++++++++++++++- .../resources/sbu/javafx/Playlist-view.fxml | 24 +++++ src/main/resources/sbu/javafx/style.css | 34 +++++++ 11 files changed, 282 insertions(+), 19 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/sbu/javafx/PlaylistController.java create mode 100644 src/main/resources/sbu/javafx/Playlist-view.fxml create mode 100644 src/main/resources/sbu/javafx/style.css diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..36767e3 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Launcher.java \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..769a78f --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 001e756..0c04b52 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file 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..e775092 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -2,7 +2,12 @@ package sbu.javafx; import javafx.application.Application; -public class Launcher{ +/** + * @Author Hesam Ghazi + * Student Number: 403222015 + */ +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); + } +} \ No newline at end of file diff --git a/src/main/java/sbu/javafx/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java index a50badc..0ac846c 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -16,7 +16,6 @@ public class MusicApp extends Application { Scene scene = new Scene(fxmlLoader.load()); stage.setTitle("Music Player"); stage.setScene(scene); - //TODO: add icon to the stage stage.show(); } diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..16cb21d 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -1,31 +1,105 @@ package sbu.javafx; import javafx.fxml.FXML; -import javafx.event.ActionEvent; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.Button; import javafx.scene.control.Label; -import javafx.scene.input.MouseEvent; +import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; public class MusicController { - // TODO: Define your UI components using the @FXML annotation. + @FXML private VBox mainContainer; + @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. + // Rows and buttons for visual feedback + @FXML private HBox row1, row2, row3; + @FXML private Button playBtn1, playBtn2, playBtn3; + + private static final List playlist = new ArrayList<>(); + private static boolean isDarkMode = false; @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. + public void initialize() { + // Keeps theme consistent if returning back from the playlist view + if (isDarkMode && mainContainer != null) { + mainContainer.getStyleClass().remove("root-light"); + mainContainer.getStyleClass().add("root-dark"); + } } - //TODO: Logic to add a specific song to the user's playlist. + @FXML + public void handleThemeToggle() { + isDarkMode = !isDarkMode; + if (isDarkMode) { + mainContainer.getStyleClass().remove("root-light"); + mainContainer.getStyleClass().add("root-dark"); + } else { + mainContainer.getStyleClass().remove("root-dark"); + mainContainer.getStyleClass().add("root-light"); + } + } + + @FXML + public void handlePlaySong1() { + nowPlayingLabel.setText("Now Playing: Song of Dawn"); + updateVisualFeedback(row1, playBtn1); + } + + @FXML + public void handlePlaySong2() { + nowPlayingLabel.setText("Now Playing: Midnight Drive"); + updateVisualFeedback(row2, playBtn2); + } + + @FXML + public void handlePlaySong3() { + nowPlayingLabel.setText("Now Playing: Echoes of You"); + updateVisualFeedback(row3, playBtn3); + } + + private void updateVisualFeedback(HBox activeRow, Button activeBtn) { + // Clear previous selections + row1.getStyleClass().remove("playing-row"); + row2.getStyleClass().remove("playing-row"); + row3.getStyleClass().remove("playing-row"); + + playBtn1.setText("Play"); + playBtn2.setText("Play"); + playBtn3.setText("Play"); + + // Set active feedback + activeRow.getStyleClass().add("playing-row"); + activeBtn.setText("Playing"); + } + + @FXML + public void handleAddToPlaylistSong1() { addToPlaylist("Song of Dawn — Alice Johnson (03:45)"); } + @FXML public void handleAddToPlaylistSong2() { addToPlaylist("Midnight Drive — The Night Owls (04:12)"); } + @FXML public void handleAddToPlaylistSong3() { addToPlaylist("Echoes of You — Luna Sky (05:08)"); } 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. + public List getPlaylist() { return playlist; } + @FXML public void openPlaylistWindow() { - //Create a new stage and show the playlist UI. + try { + Stage stage = (Stage) nowPlayingLabel.getScene().getWindow(); + FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("Playlist-view.fxml")); + Scene scene = new Scene(fxmlLoader.load()); + stage.setScene(scene); + } catch (IOException e) { + e.printStackTrace(); + } } -} +} \ No newline at end of file diff --git a/src/main/java/sbu/javafx/PlaylistController.java b/src/main/java/sbu/javafx/PlaylistController.java new file mode 100644 index 0000000..9cb2e5f --- /dev/null +++ b/src/main/java/sbu/javafx/PlaylistController.java @@ -0,0 +1,33 @@ +package sbu.javafx; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.ListView; +import javafx.stage.Stage; +import java.io.IOException; + +public class PlaylistController { + + @FXML + private ListView playlistListView; + + @FXML + public void initialize() { + + MusicController mainController = new MusicController(); + playlistListView.getItems().addAll(mainController.getPlaylist()); + } + + @FXML + public void backToMain() { + try { + Stage stage = (Stage) playlistListView.getScene().getWindow(); + FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml")); + Scene scene = new Scene(fxmlLoader.load()); + stage.setScene(scene); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ 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 306c8d3..2b5892a 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,87 @@ + + + + + + - + - + - + + + + + + +