From c5da2948c3d8c31b05bc7d6042b9a736ba38b525 Mon Sep 17 00:00:00 2001 From: neda Date: Sun, 19 Jul 2026 06:21:59 +0330 Subject: [PATCH] javafx --- .idea/misc.xml | 2 +- .idea/vcs.xml | 6 ++ src/main/java/sbu/javafx/Launcher.java | 9 +- src/main/java/sbu/javafx/MusicApp.java | 19 ++-- src/main/java/sbu/javafx/MusicController.java | 79 ++++++++++++++--- src/main/resources/sbu/javafx/App-view.fxml | 87 ++++++++++++++++++- 6 files changed, 174 insertions(+), 28 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 001e756..389a2fc 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..d112a68 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -2,7 +2,10 @@ 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); + } + +} \ 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..ed29db6 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -3,21 +3,22 @@ package sbu.javafx; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; +import javafx.scene.image.Image; import javafx.stage.Stage; -import java.io.IOException; - public class MusicApp extends Application { @Override - public void start(Stage stage) throws IOException - { - FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml")); - Scene scene = new Scene(fxmlLoader.load()); + public void start(Stage stage) throws Exception { + + FXMLLoader loader = new FXMLLoader(getClass().getResource("App-view.fxml")); + + Scene scene = new Scene(loader.load(), 700, 500); + stage.setTitle("Music Player"); + + stage.setScene(scene); - //TODO: add icon to the stage stage.show(); } - -} +} \ No newline at end of file diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..bd1f64b 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -1,31 +1,86 @@ package sbu.javafx; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; -import javafx.event.ActionEvent; +import javafx.scene.Scene; import javafx.scene.control.Label; -import javafx.scene.input.MouseEvent; +import javafx.scene.control.ListView; import javafx.scene.layout.VBox; +import javafx.stage.Stage; 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 ObservableList playlist = + FXCollections.observableArrayList(); @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. + public void playSong1() { + handlePlayAction("Shape of You"); } - //TODO: Logic to add a specific song to the user's playlist. + @FXML + public void playSong2() { + handlePlayAction("Believer"); + } + + @FXML + public void playSong3() { + handlePlayAction("Perfect"); + } + + public void handlePlayAction(String songName) { + nowPlayingLabel.setText("Now Playing: " + songName); + } + + @FXML + public void addSong1() { + addToPlaylist("Shape of You"); + } + + @FXML + public void addSong2() { + addToPlaylist("Believer"); + } + + @FXML + public void addSong3() { + addToPlaylist("Perfect"); + } 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 openPlaylistWindow() { - //Create a new stage and show the playlist UI. + + Stage stage = new Stage(); + + VBox root = new VBox(10); + + Label title = new Label("My Playlist"); + + ListView listView = new ListView<>(); + + listView.setItems(playlist); + + root.getChildren().addAll(title, listView); + + Scene scene = new Scene(root, 300, 400); + + stage.setTitle("Playlist"); + + stage.setScene(scene); + + 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 306c8d3..6d6de1d 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,89 @@ + + + + - - + - + + + + +