From e7964b2bf77517c6231b1948b13ec969f8d12b5f Mon Sep 17 00:00:00 2001 From: SoroushZ Date: Sun, 31 May 2026 14:09:46 +0330 Subject: [PATCH] T7 --- .idea/inspectionProfiles/Project_Default.xml | 6 + .idea/vcs.xml | 6 + src/main/java/sbu/javafx/Launcher.java | 8 +- src/main/java/sbu/javafx/MusicApp.java | 19 ++- src/main/java/sbu/javafx/MusicController.java | 150 ++++++++++++++++-- .../java/sbu/javafx/PlaylistController.java | 55 +++++++ src/main/java/sbu/javafx/Song.java | 34 ++++ src/main/resources/sbu/javafx/App-view.fxml | 54 ++++++- .../resources/sbu/javafx/Playlist-view.fxml | 23 +++ 9 files changed, 325 insertions(+), 30 deletions(-) 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/java/sbu/javafx/Song.java create mode 100644 src/main/resources/sbu/javafx/Playlist-view.fxml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..04e3dba --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ 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..194e244 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -2,7 +2,9 @@ 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..47dc441 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -5,19 +5,22 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Scene; 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(),900,600); + stage.setTitle("Music Player"); stage.setScene(scene); - //TODO: add icon to the stage stage.show(); } -} + public static void main(String[] args) { + launch(); + } +} \ 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..953bdb5 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -1,31 +1,151 @@ package sbu.javafx; -import javafx.fxml.FXML; import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; +import javafx.scene.Scene; import javafx.scene.control.Label; -import javafx.scene.input.MouseEvent; -import javafx.scene.layout.VBox; +import javafx.scene.control.ListView; +import javafx.scene.control.TextField; +import javafx.stage.Stage; + +import java.io.IOException; +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. + public static ArrayList playlist = + new ArrayList<>(); @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. + private ListView songsListView; + + @FXML + private Label nowPlayingLabel; + + @FXML + private TextField titleField; + + @FXML + private TextField artistField; + + @FXML + private TextField durationField; + + @FXML + public void initialize() { + + songsListView.getItems().addAll( + + new Song( + "Believer", + "Imagine Dragons", + "03:24" + ), + + new Song( + "Perfect", + "Ed Sheeran", + "04:23" + ), + + new Song( + "Yellow", + "Coldplay", + "04:29" + ) + ); } - //TODO: Logic to add a specific song to the user's playlist. + @FXML + public void addSong() { - public void addToPlaylist(String songName) { - //Add the song to a list or update a ListView. + String title = titleField.getText(); + String artist = artistField.getText(); + String duration = durationField.getText(); + + if(title.isEmpty() + || artist.isEmpty() + || duration.isEmpty()) { + + return; + } + + songsListView.getItems().add( + + new Song( + title, + artist, + duration + ) + ); + + titleField.clear(); + artistField.clear(); + durationField.clear(); } - // TODO:This method should open a new window or change the current scene to display the "Playlist" page. + @FXML + public void playSong() { - public void openPlaylistWindow() { - //Create a new stage and show the playlist UI. + Song selectedSong = + songsListView + .getSelectionModel() + .getSelectedItem(); + + if(selectedSong == null) { + return; + } + + nowPlayingLabel.setText( + "Now Playing: " + + selectedSong.getTitle() + ); } -} + + @FXML + public void addToPlaylist() { + + Song selectedSong = + songsListView + .getSelectionModel() + .getSelectedItem(); + + if(selectedSong == null) { + return; + } + + if(!playlist.contains(selectedSong)) { + playlist.add(selectedSong); + } + } + + @FXML + public void viewPlaylist(ActionEvent event) + throws IOException { + + FXMLLoader loader = + new FXMLLoader( + getClass() + .getResource( + "Playlist-view.fxml" + ) + ); + + Scene playlistScene = + new Scene( + loader.load(), + 700, + 500 + ); + + Stage stage = + (Stage)((Node)event.getSource()) + .getScene() + .getWindow(); + + stage.setScene(playlistScene); + stage.show(); + } +} \ 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..6d5430e --- /dev/null +++ b/src/main/java/sbu/javafx/PlaylistController.java @@ -0,0 +1,55 @@ +package sbu.javafx; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; +import javafx.scene.Scene; +import javafx.scene.control.ListView; +import javafx.stage.Stage; + +import java.io.IOException; + +public class PlaylistController { + + @FXML + private ListView playlistView; + + @FXML + public void initialize() { + + playlistView + .getItems() + .addAll( + MusicController.playlist + ); + } + + @FXML + public void goBack(ActionEvent event) + throws IOException { + + FXMLLoader loader = + new FXMLLoader( + getClass() + .getResource( + "App-view.fxml" + ) + ); + + Scene scene = + new Scene( + loader.load(), + 900, + 600 + ); + + Stage stage = + (Stage)((Node)event.getSource()) + .getScene() + .getWindow(); + + stage.setScene(scene); + stage.show(); + } +} \ No newline at end of file diff --git a/src/main/java/sbu/javafx/Song.java b/src/main/java/sbu/javafx/Song.java new file mode 100644 index 0000000..f032e93 --- /dev/null +++ b/src/main/java/sbu/javafx/Song.java @@ -0,0 +1,34 @@ +package sbu.javafx; + +public class Song { + + private String title; + private String artist; + private String duration; + + public Song(String title, + String artist, + String duration) { + + this.title = title; + this.artist = artist; + this.duration = duration; + } + + public String getTitle() { + return title; + } + + public String getArtist() { + return artist; + } + + public String getDuration() { + return duration; + } + + @Override + public String toString() { + return title + " | " + artist + " | " + duration; + } +} \ 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..04dca67 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,54 @@ - - + + - + - +