From d783a7fcaffba88f3c287d37ad1f4feb0884df1d Mon Sep 17 00:00:00 2001 From: ZahraSadatMirvakili Date: Wed, 27 May 2026 01:14:50 +0330 Subject: [PATCH] javafx projekt --- .idea/misc.xml | 2 +- .idea/vcs.xml | 7 + src/main/java/sbu/javafx/Launcher.java | 3 +- src/main/java/sbu/javafx/MusicApp.java | 8 +- src/main/java/sbu/javafx/MusicController.java | 132 ++++++++++++++++-- .../java/sbu/javafx/PlaylistController.java | 36 +++++ src/main/resources/sbu/javafx/App-view.fxml | 51 ++++++- .../resources/sbu/javafx/Playlist-view.fxml | 20 +++ 8 files changed, 243 insertions(+), 16 deletions(-) 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 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..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..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..5b3d166 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -3,20 +3,20 @@ 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; +import java.util.Objects; public class MusicApp extends Application { @Override - public void start(Stage stage) throws IOException - { + 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(), 800, 500); 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..8cc0779 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -1,31 +1,147 @@ 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; public class MusicController { + @FXML + private Button themeButton; - // 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. + @FXML + private Button playButton1,playButton2,playButton3; + + @FXML + private HBox row1, row2, row3; + + @FXML + private VBox mainContainer; + + + + private ArrayList playList = new ArrayList<>(); + private String currentSong = ""; + + private boolean isDarkMode = false; + + @FXML + public void toggleTheme(){ + isDarkMode = !isDarkMode; + if(isDarkMode){ + mainContainer.setStyle("-fx-padding: 20; -fx-background-color: #1e1e1e;"); + nowPlayingLabel.setStyle("-fx-padding: 15; -fx-font-style: italic; -fx-background-color: #333; -fx-text-fill: white; -fx-background-radius: 5;"); + themeButton.setText("Light Mode"); + themeButton.setStyle("-fx-background-color: #f39c12; -fx-text-fill: white; -fx-padding: 5 10; -fx-background-radius: 5;"); + }else{ + mainContainer.setStyle("-fx-padding: 20; -fx-background-color: #f0f0f0;"); + nowPlayingLabel.setStyle("-fx-padding: 15; -fx-font-style: italic; -fx-background-color: #e0e0e0; -fx-text-fill: black; -fx-background-radius: 5;"); + themeButton.setText("Dark Mode"); + themeButton.setStyle("-fx-background-color: #34495e; -fx-text-fill: white; -fx-padding: 5 10;"); + } + } + + private void resetRowHighlight() { + row1.setStyle("-fx-background-color: white; -fx-padding: 12; -fx-background-radius: 8;"); + row2.setStyle("-fx-background-color: white; -fx-padding: 12; -fx-background-radius: 8;"); + row3.setStyle("-fx-background-color: white; -fx-padding: 12; -fx-background-radius: 8;"); + } + + private void resetAllPlayButtons(){ + playButton1.setText("▶️Play"); + playButton1.setStyle("-fx-background-color: #27ae60; -fx-text-fill: white; -fx-background-radius: 5;"); + + playButton2.setText("▶️Play"); + playButton2.setStyle("-fx-background-color: #27ae60; -fx-text-fill: white; -fx-background-radius: 5;"); + + playButton3.setText("▶️Play"); + playButton3.setStyle("-fx-background-color: #27ae60; -fx-text-fill: white; -fx-background-radius: 5;"); + } + + @FXML + public void playSong1() { + resetAllPlayButtons(); + resetRowHighlight(); + currentSong = "Song of Dawn - Alice Johnson"; + nowPlayingLabel.setText("Now Playing: "+ currentSong); + playButton1.setText("⏸️Playing"); + playButton1.setStyle("-fx-background-color: #f39c12; -fx-text-fill: white; -fx-background-radius: 5;"); + } + + @FXML + public void playSong2() { + resetAllPlayButtons(); + resetRowHighlight(); + currentSong = "Midnight Drive - The Night Owls"; + nowPlayingLabel.setText("Now Playing: "+ currentSong); + playButton2.setText("⏸️Playing"); + playButton2.setStyle("-fx-background-color: #f39c12; -fx-text-fill: white; -fx-background-radius: 5;"); + } + + @FXML + public void playSong3() { + resetAllPlayButtons(); + resetRowHighlight(); + currentSong = "Echoes of You - Luna Sky"; + nowPlayingLabel.setText("Now Playing: "+ currentSong); + playButton3.setText("⏸️Playing"); + playButton3.setStyle("-fx-background-color: #f39c12; -fx-text-fill: white; -fx-background-radius: 5;"); + } @FXML public void handlePlayAction() { //Update labels, change button icons, etc. } - //TODO: Logic to add a specific song to the user's playlist. + @FXML + public void addSong1ToPlaylist() { + playList.add("Song of Dawn - Alice Johnson (03:45)"); + System.out.println("Added: Song of Dawn"); + } + + @FXML + public void addSong2ToPlaylist() { + playList.add("Midnight Drive - The Night Owls (04:12)"); + System.out.println("Added: Midnight Drive"); + } + + @FXML + public void addSong3ToPlaylist() { + playList.add("Echoes of You - Luna Sky (05:08)"); + System.out.println("Added: Echoes of You"); + } public void addToPlaylist(String songName) { //Add the song to a list or update a ListView. } - // 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. + try{ + FXMLLoader loader = new FXMLLoader(getClass().getResource("Playlist-view.fxml")); + VBox root = loader.load(); + + PlaylistController playlistController = loader.getController(); + playlistController.setPlaylist(playList); + + Scene scene = new Scene(root, 450 , 400); + Stage playlistStage = new Stage(); + playlistStage.setTitle("Playlist"); + playlistStage.setScene(scene); + playlistStage.show(); + + } catch (IOException e) { + e.getMessage(); + } } } diff --git a/src/main/java/sbu/javafx/PlaylistController.java b/src/main/java/sbu/javafx/PlaylistController.java new file mode 100644 index 0000000..35b5037 --- /dev/null +++ b/src/main/java/sbu/javafx/PlaylistController.java @@ -0,0 +1,36 @@ +package sbu.javafx; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import java.util.ArrayList; + +public class PlaylistController { + + @FXML + private VBox playlistContainer; + + public void setPlaylist(ArrayList playlist){ + playlistContainer.getChildren().clear(); + + if (playlist.isEmpty()){ + Label emptyLabel = new Label("Playlist is empty. Add some songs!"); + emptyLabel.setStyle("-fx-text-fill: #999; -fx-font-style: italic;"); + playlistContainer.getChildren().add(emptyLabel); + }else { + for (int i = 0; i < playlist.size(); i++) { + Label songLabel = new Label((i+1) + ". " + playlist.get(i)); + songLabel.setStyle("-fx-padding: 5; -fx-font-size: 14px;"); + playlistContainer.getChildren().add(songLabel); + } + } + } + + @FXML + public void closePlaylistWindow(ActionEvent actionEvent) { + Stage stage = (Stage) playlistContainer.getScene().getWindow(); + stage.close(); + } +} diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 306c8d3..3651ac7 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,55 @@ - + + + - + + +