Develop #1

Merged
MehrdadShirvani merged 5 commits from develop into main 2026-07-10 16:05:40 +00:00
16 changed files with 332 additions and 18 deletions
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
+9 -2
View File
@@ -11,7 +11,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <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> <dependencies>
<dependency> <dependency>
@@ -24,8 +24,15 @@
<artifactId>javafx-fxml</artifactId> <artifactId>javafx-fxml</artifactId>
<version>21</version> <version>21</version>
</dependency> </dependency>
<dependency>
<dependency> <groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>21</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version> <version>${junit.version}</version>
+2 -1
View File
@@ -4,5 +4,6 @@ import javafx.application.Application;
public class Launcher{ public class Launcher{
public static void main(String[] args) { public static void main(String[] args) {
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) } Application.launch(MusicApp.class);
}
} }
+10 -2
View File
@@ -4,7 +4,8 @@ import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.scene.image.Image;
import java.awt.*;
import java.io.IOException; import java.io.IOException;
public class MusicApp extends Application { public class MusicApp extends Application {
@@ -14,9 +15,16 @@ public class MusicApp extends Application {
{ {
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml")); FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
Scene scene = new Scene(fxmlLoader.load()); Scene scene = new Scene(fxmlLoader.load());
String lightStyle = getClass().getResource("light.css").toExternalForm();
scene.getStylesheets().add(lightStyle);
stage.setTitle("Music Player"); stage.setTitle("Music Player");
stage.setScene(scene); stage.setScene(scene);
//TODO: add icon to the stage
Image icon = new Image(getClass().getResourceAsStream("icon.png"));
stage.getIcons().add(icon);
stage.show(); stage.show();
} }
+158 -10
View File
@@ -1,31 +1,179 @@
package sbu.javafx; package sbu.javafx;
import javafx.fxml.FXML; 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.control.Label;
import javafx.scene.input.MouseEvent; import javafx.scene.control.ListView;
import javafx.scene.layout.VBox; import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class MusicController { public class MusicController {
// TODO: Define your UI components using the @FXML annotation. // TODO: Define your UI components using the @FXML annotation.
@FXML private ListView<String> lvSongs;
@FXML private Label lblStatus;
@FXML private Button btnPlayStop;
@FXML private Button btnTheme;
private int previousSongIndex = -1;
private MediaPlayer mediaPlayer;
private ArrayList<String> playlist = new ArrayList<>();
private String[] songsArray = {"Arcade Duncan Laurence 3.07",
"How i love you Engelbert 4.20",
"Memories Conan Gray 4.09",
"Night Changes One Direction 3.47",
"Careless Whisper George Michael 5.00"
};
@FXML public void initialize() { lvSongs.getItems().setAll(songsArray); }
//TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. //TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing.
public String songName(int a)
{
String songName = "";
if (a == 0) songName = "Arcade";
else if (a == 1) songName = "How i love you";
else if (a == 2) songName = "Memories";
else if (a == 3) songName = "Night Changes";
else songName = "Careless Whisper";
return songName;
}
@FXML @FXML
public void handlePlayAction() { public void handlePlayAction()
//Update labels, change button icons, etc. {
String selectedSong = lvSongs.getSelectionModel().getSelectedItem();
int newSongIndex = lvSongs.getSelectionModel().getSelectedIndex();
boolean isNewSong = (newSongIndex != previousSongIndex);
if (selectedSong == null)
{
lblStatus.setText("Please choose a song");
return;
}
if (isNewSong)
{
if (mediaPlayer != null)
{
mediaPlayer.dispose();
mediaPlayer = null;
}
String filePath = "src/main/resources/sbu/javafx/songs/" + songName(lvSongs.getSelectionModel().getSelectedIndex()) + ".mp3";
File file = new File(filePath);
try {
Media media = new Media(file.toURI().toString());
mediaPlayer = new MediaPlayer(media);
mediaPlayer.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
mediaPlayer.stop();
btnPlayStop.setText("Play ▶");
lblStatus.setText("Finished");
}
});
mediaPlayer.play();
btnPlayStop.setText("Paused ⏸");
lblStatus.setText("Playing : " + songName(lvSongs.getSelectionModel().getSelectedIndex()));
previousSongIndex = newSongIndex;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
else
{
if (mediaPlayer.getStatus() == MediaPlayer.Status.PLAYING)
{
mediaPlayer.pause();
btnPlayStop.setText("Play ▶");
lblStatus.setText("Paused");
}
else if (mediaPlayer.getStatus() == MediaPlayer.Status.PAUSED)
{
mediaPlayer.play();
btnPlayStop.setText("Pause ⏸");
lblStatus.setText("Playing: " + songName(lvSongs.getSelectionModel().getSelectedIndex()));
}
else
{
mediaPlayer.play();
btnPlayStop.setText("Pause ⏸");
lblStatus.setText("Playing: " + songName(lvSongs.getSelectionModel().getSelectedIndex()));
}
}
} }
//TODO: Logic to add a specific song to the user's playlist. //TODO: Logic to add a specific song to the user's playlist.
public void addToPlaylist(String songName) { @FXML
//Add the song to a list or update a ListView. public void addToPlaylist()
{
String selectedSong = lvSongs.getSelectionModel().getSelectedItem();
if (selectedSong == null)
{
lblStatus.setText("Please choose a song");
return;
}
if (!playlist.contains(selectedSong))
{
playlist.add(selectedSong);
lblStatus.setText(songName(lvSongs.getSelectionModel().getSelectedIndex()) + " added to playList");
}
else lblStatus.setText(songName(lvSongs.getSelectionModel().getSelectedIndex()) + " already exists");
} }
// TODO:This method should open a new window or change the current scene to display the "Playlist" page. // TODO:This method should open a new window or change the current scene to display the "Playlist" page.
public void openPlaylistWindow() { public void openPlaylistWindow()
//Create a new stage and show the playlist UI. {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Playlist-view.fxml"));
Scene scene = null;
try {
scene = new Scene(loader.load());
} catch (IOException e) {
throw new RuntimeException(e);
}
PlayListController controller = loader.getController();
controller.setPlaylist(playlist);
Stage stage = new Stage();
stage.setTitle("Playlist");
stage.setScene(scene);
stage.show();
} }
}
@FXML
private void toggleTheme()
{
if (!btnTheme.getText().contains("Light"))
{
btnTheme.getScene().getStylesheets().clear();
btnTheme.getScene().getStylesheets().add(getClass().getResource("style.css").toExternalForm());
btnTheme.setText("Light Mode");
}
else
{
btnTheme.getScene().getStylesheets().clear();
btnTheme.getScene().getStylesheets().add(getClass().getResource("light.css").toExternalForm());
btnTheme.setText("Dark Mode");
}
}
}
@@ -0,0 +1,14 @@
package sbu.javafx;
import java.util.ArrayList;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
public class PlayListController
{
@FXML private ListView<String> lvPlaylist;
public void setPlaylist(ArrayList<String> playlist)
{
lvPlaylist.getItems().addAll(playlist);
}
}
+25 -3
View File
@@ -1,8 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.VBox?> <?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! --> <?import javafx.geometry.Insets?>
<VBox alignment="CENTER" spacing="15.0" xmlns:fx="http://javafx.com/fxml" fx:controller="sbu.javafx.MusicController">
<padding>
<Insets bottom="20" left="300" right="300" top="20"/>
</padding>
</VBox> <Label fx:id="lblStatus" text="Music Player" style="-fx-font-size: 18px; -fx-font-weight: bold;"/>
<ListView fx:id="lvSongs" prefHeight="200.0" prefWidth="350.0"/>
<HBox spacing="10" alignment="CENTER">
<Button fx:id="btnPlayStop" text="PLay ▶" onAction="#handlePlayAction" prefWidth="200"/>
<Button fx:id="btnTheme" text="Dark Mode" onAction="#toggleTheme" />
</HBox>
<VBox spacing="10"/>
<Button text="Add to playlist " onAction="#addToPlaylist" prefWidth="300"/>
<VBox spacing="10"/>
<Button fx:id="btnViewPlaylist" text="Show Playlist" onAction="#openPlaylistWindow" prefWidth="300"/>
</VBox>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.VBox?>
<VBox alignment="TOP_CENTER" spacing="10.0" xmlns:fx="http://javafx.com/fxml" fx:controller="sbu.javafx.PlayListController">
<Label text="Your PlayList : " style="-fx-font-size: 20px; -fx-font-weight: bold;"/>
<ListView fx:id="lvPlaylist" prefHeight="300.0" prefWidth="300.0"/>
</VBox>
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+49
View File
@@ -0,0 +1,49 @@
.root {
-fx-background-color: #e0e0e0;
-fx-text-fill: black;
}
.label {
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-text-fill: #ff1493;
}
.list-view {
-fx-background-color: white;
-fx-border-color: #ff1493;
-fx-border-width: 2px;
-fx-background-radius: 10px;
-fx-border-radius: 10px;
}
.list-cell {
-fx-background-color: white;
-fx-text-fill: black;
-fx-font-weight: bold;
-fx-border-color: transparent;
-fx-background-radius: 10px;
-fx-border-radius: 10px;
}
.list-cell:selected {
-fx-background-color: #ffb6c1;
-fx-text-fill: black;
}
.button {
-fx-background-color: #ffe4e1;
-fx-text-fill: black;
-fx-font-weight: bold;
-fx-padding: 10px;
-fx-cursor: hand;
-fx-border-color: #ff1493;
-fx-border-width: 2px;
-fx-background-radius: 50px;
-fx-border-radius: 50px;
}
.button:hover {
-fx-background-color: #ffc0cb;
-fx-border-color: #ff1493;
}
Binary file not shown.
Binary file not shown.
+49
View File
@@ -0,0 +1,49 @@
.root {
-fx-background-color: #1e1e1e;
-fx-text-fill: #ffffff;
}
.label {
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-text-fill: #ff69b4;
}
.list-view {
-fx-background-color: #2d2d2d;
-fx-border-color: #ff1493;
-fx-border-width: 2px;
-fx-background-radius: 10px;
-fx-border-radius: 10px;
}
.list-cell {
-fx-background-color: #2d2d2d;
-fx-text-fill: #ffffff;
-fx-font-weight: bold;
-fx-border-color: transparent;
}
.list-cell:selected {
-fx-background-color: #4a002a;
-fx-text-fill: #ffffff;
-fx-background-radius: 10px;
-fx-border-radius: 10px;
}
.button {
-fx-background-color: #4a4a4a;
-fx-text-fill: #ffffff;
-fx-font-weight: bold;
-fx-padding: 10px;
-fx-cursor: hand;
-fx-border-color: #ff1493;
-fx-border-width: 2px;
-fx-background-radius: 50px;
-fx-border-radius: 50px;
}
.button:hover {
-fx-background-color: #5a5a5a;
-fx-border-color: #ff69b4;
}