From 7fb6d4fdb4b012d8d4bcca552e6b52b64d9df4f2 Mon Sep 17 00:00:00 2001 From: navid Date: Fri, 29 May 2026 21:53:29 +0330 Subject: [PATCH] tamrin 7 --- .idea/vcs.xml | 7 ++ src/main/java/sbu/javafx/Launcher.java | 5 +- src/main/java/sbu/javafx/MusicApp.java | 10 +- src/main/java/sbu/javafx/MusicController.java | 104 ++++++++++++++++-- src/main/resources/sbu/javafx/App-view.fxml | 43 +++++++- src/main/resources/sbu/javafx/dextericon.png | Bin 0 -> 67677 bytes 6 files changed, 152 insertions(+), 17 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 src/main/resources/sbu/javafx/dextericon.png 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/src/main/java/sbu/javafx/Launcher.java b/src/main/java/sbu/javafx/Launcher.java index c288d10..06d78e7 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); + } } diff --git a/src/main/java/sbu/javafx/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java index a50badc..e9cd3b4 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -3,6 +3,8 @@ package sbu.javafx; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.scene.paint.Color; import javafx.stage.Stage; import java.io.IOException; @@ -13,10 +15,14 @@ public class MusicApp extends Application { public void start(Stage stage) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml")); - Scene scene = new Scene(fxmlLoader.load()); + Scene scene = new Scene(fxmlLoader.load(),600,350); stage.setTitle("Music Player"); stage.setScene(scene); - //TODO: add icon to the stage + Image icon = new Image(getClass().getResource("dextericon.png").toExternalForm()); + stage.getIcons().add(icon); + stage.setTitle("Dexter Music Player"); + stage.setScene(scene); + stage.show(); } diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..a4d2a4d 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -2,30 +2,112 @@ package sbu.javafx; import javafx.fxml.FXML; import javafx.event.ActionEvent; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Button; import javafx.scene.control.Label; 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 lblNowPlaying; @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. + private Button btnPlay1, btnPlay2, btnPlay3; + + @FXML + private Button btnAdd1, btnAdd2, btnAdd3; + + @FXML + private Button btnOpenPlaylist; + private ArrayList playlist = new ArrayList<>(); + private Scene mainScene; + + @FXML + public void initialize() { + mainScene = lblNowPlaying.getScene(); + } + + + @FXML + public void handlePlayAction(ActionEvent event) { + Button clickedButton = (Button) event.getSource(); + String songName = ""; + + if (clickedButton == btnPlay1) { + songName = "Song of Dawn - Alice Johnson"; + } else if (clickedButton == btnPlay2) { + songName = "Midnight Drive - The Night Owls"; + } else if (clickedButton == btnPlay3) { + songName = "Echoes of You - Luna Sky"; + } + + if (lblNowPlaying != null) { + lblNowPlaying.setText("Now Playing: " + songName); + } + } + + @FXML + public void handleAddToPlaylistAction(ActionEvent event) { + Button clickedButton = (Button) event.getSource(); + String songName = ""; + + if (clickedButton == btnAdd1) { + songName = "Song of Dawn - Alice Johnson"; + } else if (clickedButton == btnAdd2) { + songName = "Midnight Drive - The Night Owls"; + } else if (clickedButton == btnAdd3) { + songName = "Echoes of You - Luna Sky"; + } + + addToPlaylist(songName); } - //TODO: Logic to add a specific song to the user's playlist. public void addToPlaylist(String songName) { - //Add the song to a list or update a ListView. + if (songName != null && !songName.isEmpty()) { + playlist.add(songName); + System.out.println("Added: " + songName); + } } - // TODO:This method should open a new window or change the current scene to display the "Playlist" page. - public void openPlaylistWindow() { - //Create a new stage and show the playlist UI. + public void openPlaylistWindow(ActionEvent event) { + Stage currentStage = (Stage) ((Button) event.getSource()).getScene().getWindow(); + mainScene = currentStage.getScene(); + + VBox playlistLayout = new VBox(10); + playlistLayout.setStyle("-fx-padding: 20; -fx-alignment: top-center;"); + + Label titleLabel = new Label("Your Playlist:"); + titleLabel.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;"); + playlistLayout.getChildren().add(titleLabel); + + if (playlist.isEmpty()) { + playlistLayout.getChildren().add(new Label("Your playlist is empty.")); + } else { + for (String song : playlist) { + playlistLayout.getChildren().add(new Label("- " + song)); + } + } + + Button backButton = new Button("Back to Music Player"); + backButton.setOnAction(e -> { + Stage stage = (Stage) backButton.getScene().getWindow(); + stage.setScene(mainScene); + stage.setTitle("Music Player"); + }); + playlistLayout.getChildren().add(backButton); + + Scene playlistScene = new Scene(playlistLayout, 400, 500); + currentStage.setScene(playlistScene); + currentStage.setTitle("Playlist"); + } + } diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 306c8d3..cd33b6a 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,47 @@ - + + + - + + + + +