diff --git a/.idea/misc.xml b/.idea/misc.xml index 001e756..fe43c29 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/pom.xml b/pom.xml index e45147d..d6fdf55 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,8 @@ UTF-8 -5.10.2 + 5.10.2 + @@ -19,13 +20,20 @@ javafx-controls 21 + org.openjfx javafx-fxml 21 - + + org.openjfx + javafx-graphics + 21 + + + org.junit.jupiter junit-jupiter-api ${junit.version} @@ -36,7 +44,8 @@ junit-jupiter-engine ${junit.version} test - + + @@ -49,16 +58,19 @@ 23 + org.openjfx javafx-maven-plugin 0.0.8 + + sbu.javafx.Launcher + - default-cli - sbu.javafx/sbu.javafx.MusicApp + sbu.javafx.MusicApp app app app diff --git a/src/main/java/sbu/javafx/Launcher.java b/src/main/java/sbu/javafx/Launcher.java index c288d10..d24fc84 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -1,8 +1,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) } -} + // برنامه اصلی ما یعنی MusicApp را استارت می‌زند + MusicApp.main(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..5b1511b 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -4,20 +4,25 @@ import javafx.application.Application; 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")); + public void start(Stage stage) throws IOException { + // لود شدن لایه گرافیکی + FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("/sbu/javafx/App-view.fxml")); Scene scene = new Scene(fxmlLoader.load()); + + // تنظیمات عنوان پنجره stage.setTitle("Music Player"); stage.setScene(scene); - //TODO: add icon to the stage + + // نمایش پنجره به کاربر stage.show(); } -} + public static void main(String[] args) { + launch(args); + } +} \ 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..993cbf9 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -1,31 +1,96 @@ package sbu.javafx; import javafx.fxml.FXML; -import javafx.event.ActionEvent; +import javafx.fxml.FXMLLoader; +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; +import java.util.ArrayList; public class MusicController { - // TODO: Define your UI components using the @FXML annotation. + // متصل کردن لیبل وضعیت آهنگ جاری به محیط Scene Builder + @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 ArrayList playlist = new ArrayList<>(); + + // متدهای کلیک روی دکمه Play برای ۳ آهنگ مختلف + @FXML + public void playSong1() { + nowPlayingLabel.setText("Now Playing: Blinding Lights - The Weeknd"); + } @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. + public void playSong2() { + nowPlayingLabel.setText("Now Playing: Shape of You - Ed Sheeran"); } - //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. + @FXML + public void playSong3() { + nowPlayingLabel.setText("Now Playing: Bohemian Rhapsody - Queen"); } - // TODO:This method should open a new window or change the current scene to display the "Playlist" page. + // ۴. متدهای کلیک روی دکمه Add to Playlist برای ۳ آهنگ مختلف (بخش ۴ تمرین) + @FXML + public void addSong1ToPlaylist() { + addToPlaylist("Blinding Lights - The Weeknd (03:20)"); + } + @FXML + public void addSong2ToPlaylist() { + addToPlaylist("Shape of You - Ed Sheeran (03:53)"); + } + + @FXML + public void addSong3ToPlaylist() { + addToPlaylist("Bohemian Rhapsody - Queen (05:55)"); + } + + // متد کمکی برای اضافه کردن نام آهنگ به ArrayList (جلوگیری از اسم تکراری) + private void addToPlaylist(String songName) { + if (!playlist.contains(songName)) { + playlist.add(songName); + System.out.println("Added: " + songName); // چاپ در کنسول برای اطمینان + } + } + + // متد باز کردن صفحه لیست پخش در یک Scene جدید + @FXML public void openPlaylistWindow() { - //Create a new stage and show the playlist UI. + // پیدا کردن پنجره (Stage) جاری از روی یکی از المان‌های صفحه + Stage currentStage = (Stage) nowPlayingLabel.getScene().getWindow(); + + // ساخت یک باکس عمودی (VBox) برای چیدمان صفحه جدید + VBox layout = new VBox(15); + layout.setStyle("-fx-padding: 20; -fx-alignment: center;"); + + Label titleLabel = new Label("My Playlist"); + titleLabel.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;"); + + // استفاده از ابزار ListView برای نشان دادن لیست آهنگ‌ها + ListView listView = new ListView<>(); + listView.getItems().addAll(playlist); // ریختن آهنگ‌های داخل ArrayList درون لیست‌ویو + + // دکمه بازگشت به پلیر اصلی + javafx.scene.control.Button backButton = new javafx.scene.control.Button("Back to Player"); + backButton.setOnAction(e -> { + try { + // لود مجدد صفحه اول پلیر + FXMLLoader loader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml")); + currentStage.setScene(new Scene(loader.load())); + } catch (Exception ex) { + ex.printStackTrace(); + } + }); + + // اضافه کردن همه المان‌ها به دایرکتوری صفحه جدید + layout.getChildren().addAll(titleLabel, listView, backButton); + + // جابه‌جایی به Scene جدید بدون باز شدن پنجره اضافی + Scene playlistScene = new Scene(layout, 380, 450); + currentStage.setScene(playlistScene); } -} +} \ 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..70cb4d4 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,39 @@ + + - + - + - +