Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac961cd1a0 |
Generated
+1
-1
@@ -8,7 +8,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="23" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_26" default="true" project-jdk-name="homebrew-26" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<junit.version>5.10.2</junit.version> </properties>
|
||||
<junit.version>5.10.2</junit.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -19,12 +20,19 @@
|
||||
<artifactId>javafx-controls</artifactId>
|
||||
<version>21</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-fxml</artifactId>
|
||||
<version>21</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-graphics</artifactId>
|
||||
<version>21</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
@@ -36,7 +44,8 @@
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency> </dependencies>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -49,16 +58,19 @@
|
||||
<target>23</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>0.0.8</version>
|
||||
<configuration>
|
||||
<mainClass>sbu.javafx.Launcher</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<!-- Default configuration for running with: mvn clean javafx:run -->
|
||||
<id>default-cli</id>
|
||||
<configuration>
|
||||
<mainClass>sbu.javafx/sbu.javafx.MusicApp</mainClass>
|
||||
<mainClass>sbu.javafx.MusicApp</mainClass>
|
||||
<launcher>app</launcher>
|
||||
<jlinkZipName>app</jlinkZipName>
|
||||
<jlinkImageName>app</jlinkImageName>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package sbu.javafx;
|
||||
|
||||
import javafx.application.Application;
|
||||
|
||||
public class Launcher {
|
||||
public static void main(String[] args) {
|
||||
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) }
|
||||
// برنامه اصلی ما یعنی MusicApp را استارت میزند
|
||||
MusicApp.main(args);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
|
||||
<!-- TODO: Add your code here! -->
|
||||
<VBox xmlns="http://javafx.com/fxml/1" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="sbu.javafx.MusicController"
|
||||
alignment="CENTER" spacing="20.0"
|
||||
style="-fx-padding: 30; -fx-background-color: #2c3e50;">
|
||||
|
||||
<Label text="SBU Music Player" style="-fx-font-size: 20px; -fx-text-fill: white; -fx-font-weight: bold;"/>
|
||||
|
||||
<Label fx:id="nowPlayingLabel" text="No Song Playing" style="-fx-font-size: 14px; -fx-text-fill: #ecf0f1;"/>
|
||||
|
||||
<VBox spacing="10.0" alignment="CENTER" style="-fx-background-color: #34495e; -fx-padding: 15; -fx-background-radius: 10;">
|
||||
<HBox spacing="15.0" alignment="CENTER">
|
||||
<Label text="Blinding Lights" style="-fx-text-fill: white;"/>
|
||||
<Button text="Play" onAction="#playSong1"/>
|
||||
<Button text="Add" onAction="#addSong1ToPlaylist"/>
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="15.0" alignment="CENTER">
|
||||
<Label text="Shape of You" style="-fx-text-fill: white;"/>
|
||||
<Button text="Play" onAction="#playSong2"/>
|
||||
<Button text="Add" onAction="#addSong2ToPlaylist"/>
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="15.0" alignment="CENTER">
|
||||
<Label text="Bohemian Rhapsody" style="-fx-text-fill: white;"/>
|
||||
<Button text="Play" onAction="#playSong3"/>
|
||||
<Button text="Add" onAction="#addSong3ToPlaylist"/>
|
||||
</HBox>
|
||||
</VBox>
|
||||
|
||||
<Button text="View My Playlist" onAction="#openPlaylistWindow" style="-fx-background-color: #e74c3c; -fx-text-fill: white; -fx-font-weight: bold;"/>
|
||||
|
||||
</VBox>
|
||||
Reference in New Issue
Block a user