Develop #1

Merged
Meraj merged 3 commits from develop into main 2026-08-01 00:26:53 +00:00
13 changed files with 431 additions and 10 deletions
Generated
+7
View File
@@ -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>
+5
View File
@@ -14,6 +14,11 @@
<junit.version>5.10.2</junit.version> </properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>21</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
+7 -1
View File
@@ -3,6 +3,12 @@ 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) }
Application.launch(MusicApp.class ,args);
}
}
+2
View File
@@ -14,8 +14,10 @@ public class MusicApp extends Application {
{
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
Scene scene = new Scene(fxmlLoader.load());
stage.setTitle("Music Player");
stage.setScene(scene);
//TODO: add icon to the stage
stage.show();
}
+220 -5
View File
@@ -2,30 +2,245 @@ package sbu.javafx;
import javafx.fxml.FXML;
import javafx.event.ActionEvent;
import javafx.scene.control.Label;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.fxml.FXML;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.control.ListView;
import javafx.stage.Stage;
import javafx.scene.control.Slider;
import javafx.scene.control.Label;
import javafx.util.Duration;
import javafx.scene.control.ToggleButton;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Objects;
public class MusicController {
ArrayList<String> playls = new ArrayList<>() ;
@FXML
private ListView<String> playlistview ;
@FXML
private Label nowPlayingLabel ;
@FXML
private Slider timeSlider ;
@FXML
private Label timeLabel ;
@FXML
private Slider volumeSlider ;
@FXML
private ToggleButton themeButton ;
@FXML
public void toggleTheme() {
Scene scene = themeButton.getScene();
scene.getStylesheets().clear();
if(themeButton.isSelected()) {
scene.getStylesheets().add(
getClass()
.getResource("dark-theme.css")
.toExternalForm()
);
themeButton.setText("Dark Mode");
}
else {
scene.getStylesheets().add(
getClass()
.getResource("light-theme.css")
.toExternalForm()
);
themeButton.setText("Light Mode");
}
}
// 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.
private Button PlayButton ;
private MediaPlayer mediaPlayer;
private boolean IsPlay = false ;
@FXML
public void handlePlayAction() {
public void Play( Button btn)
{
if (!IsPlay)
{
btn.setText("stop");
IsPlay = true ;
}
else if (IsPlay)
{
btn.setText("play");
IsPlay = false ;
}
}
@FXML
public void handlePlayAction(ActionEvent event) {
String songPath = "";
Button button =
(Button) event.getSource();
//Update labels, change button icons, etc.
if(button.getId().equals("1")) {
if (!IsPlay) {
songPath = "/1.mp3";
Play( button);
nowPlayingLabel.setText("Rahe Meykhaneh");
}
else
{
mediaPlayer.stop();
Play( button);
nowPlayingLabel.setText("Stop");
}
}
else if(button.getId().equals("2")) {
if (!IsPlay) {
songPath = "/2.mp3";
Play( button);
nowPlayingLabel.setText("Saghi Bia");
}
else
{
mediaPlayer.stop();
Play( button);
nowPlayingLabel.setText("Stop");
}
}
else if(button.getId().equals("3")) {
if (!IsPlay) {
songPath = "/3.mp3";
Play( button);
nowPlayingLabel.setText("Mara Be Hich Bedady");
}
else
{
mediaPlayer.stop();
Play(button);
nowPlayingLabel.setText("Stop");
}
}
Media media = new Media(
getClass().getResource(songPath)
.toExternalForm()
);
mediaPlayer = new MediaPlayer(media);
mediaPlayer.setVolume(
volumeSlider.getValue() / 100.0
);
volumeSlider.valueProperty().addListener(
(obs, oldVal, newVal) -> {
if(mediaPlayer != null) {
mediaPlayer.setVolume(
newVal.doubleValue() / 100.0
);
}
}
);
mediaPlayer.setOnReady(() -> {
timeSlider.setMax(mediaPlayer.getTotalDuration().toSeconds());
});
mediaPlayer.currentTimeProperty().addListener(
(obs, oldTime, newTime) -> {
timeSlider.setValue(
newTime.toSeconds()
);
timeLabel.setText(
(int)newTime.toMinutes()
+ ":"
+ (int)(newTime.toSeconds() % 60)
);
}
);
timeSlider.setOnMouseReleased(event2 -> {
mediaPlayer.seek(
Duration.seconds(
timeSlider.getValue()
)
);
});
mediaPlayer.play();
}
//TODO: Logic to add a specific song to the user's playlist.
public void addToPlaylist(String songName) {
public void addToPlaylist( ActionEvent event) {
//Add the song to a list or update a ListView.
Button button =
(Button) event.getSource();
if(!playls.contains(button.getUserData().toString())) {
playls.add(button.getUserData().toString());
}
System.out.println(playls);
}
// TODO:This method should open a new window or change the current scene to display the "Playlist" page.
public void openPlaylistWindow() {
@FXML
public void openPlaylistWindow () throws IOException {
//Create a new stage and show the playlist UI.
System.out.println("Button Clicked");
System.out.println(
getClass().getResource("App-view2.fxml")
);
FXMLLoader loader = new FXMLLoader(
getClass().getResource("App-view2.fxml")
);
Parent root = loader.load();
MusicController controller = loader.getController();
controller.playlistview.getItems().addAll(playls);
Stage stage = new Stage() ;
stage.setTitle("Playlist");
stage.setScene(new Scene(root));
stage.show();
playlistview.getItems().addAll(playls) ;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

+135 -2
View File
@@ -1,8 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<!-- TODO: Add your code here! -->
<VBox alignment="CENTER" xmlns="http://javafx.com/javafx/26" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sbu.javafx.MusicController">
<children>
<Label alignment="CENTER" prefHeight="23.0" prefWidth="576.0" text="Music Player">
<font>
<Font name="Mongolian Baiti" size="20.0" />
</font>
</Label>
<HBox prefHeight="0.0" prefWidth="578.0">
<children>
<AnchorPane prefHeight="54.0" prefWidth="577.0">
<children>
<Label layoutX="370.0" layoutY="8.0" prefHeight="18.0" prefWidth="86.0" text="Add To PlayList" />
<Label layoutX="270.0" layoutY="8.0" text="Duration " />
<Label layoutX="523.0" layoutY="8.0" text="play" />
<Label layoutX="148.0" layoutY="8.0" prefHeight="18.0" prefWidth="74.0" text="Artist Name" />
<Label layoutX="43.0" layoutY="8.0" text="Song Title" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#ffffff00" height="34.0" layoutX="7.0" stroke="BLACK" strokeType="INSIDE" width="567.0" />
</children>
</AnchorPane>
</children>
</HBox>
<HBox prefHeight="64.0" prefWidth="578.0">
<children>
<AnchorPane prefHeight="65.0" prefWidth="578.0">
<children>
<Label layoutX="32.0" layoutY="23.0" text="Rahe Meykhaneh" />
<Label layoutX="169.0" layoutY="23.0" text="M.Shajarian" />
<Label layoutX="275.0" layoutY="23.0" text="06:19" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="48.0" layoutX="7.0" layoutY="8.0" stroke="BLACK" strokeType="INSIDE" width="567.0" />
<Button fx:id="4" layoutX="366.0" layoutY="18.0" mnemonicParsing="false" onAction="#addToPlaylist" prefHeight="26.0" prefWidth="86.0" text="Add To PlayList" userData="Rahe Meykhaneh --- M.Shajarian">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="1" layoutX="520.0" layoutY="20.0" mnemonicParsing="false" onAction="#handlePlayAction" prefHeight="22.0" prefWidth="34.0" text="Play">
<font>
<Font size="10.0" />
</font>
</Button>
</children>
</AnchorPane>
</children>
</HBox>
<HBox prefHeight="64.0" prefWidth="578.0">
<children>
<AnchorPane prefHeight="65.0" prefWidth="578.0">
<children>
<Label layoutX="32.0" layoutY="23.0" text="Saghi Bia" />
<Label layoutX="169.0" layoutY="23.0" text="M.Shajarian" />
<Label layoutX="275.0" layoutY="23.0" text="01:52" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="48.0" layoutX="7.0" layoutY="8.0" stroke="BLACK" strokeType="INSIDE" width="567.0" />
<Button fx:id="5" layoutX="366.0" layoutY="19.0" mnemonicParsing="false" onAction="#addToPlaylist" prefHeight="26.0" prefWidth="86.0" text="Add To PlayList" userData="Saghi Bia --- M.Shajarian">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="2" layoutX="520.0" layoutY="21.0" mnemonicParsing="false" onAction="#handlePlayAction" prefHeight="22.0" prefWidth="34.0" text="Play">
<font>
<Font size="10.0" />
</font>
</Button>
</children>
</AnchorPane>
</children>
</HBox>
<HBox prefHeight="64.0" prefWidth="578.0">
<children>
<AnchorPane prefHeight="65.0" prefWidth="578.0">
<children>
<Label layoutX="32.0" layoutY="23.0" text="Mara Be Hich Bedady" />
<Label layoutX="169.0" layoutY="23.0" text="M.Shajarian" />
<Label layoutX="275.0" layoutY="23.0" text="16:59" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="48.0" layoutX="7.0" layoutY="8.0" stroke="BLACK" strokeType="INSIDE" width="567.0" />
<Button fx:id="6" layoutX="365.0" layoutY="18.0" mnemonicParsing="false" onAction="#addToPlaylist" prefHeight="26.0" prefWidth="86.0" text="Add To PlayList" userData="Mara Be Hich Bedady --- M.Shajarian">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="3" layoutX="518.0" layoutY="20.0" mnemonicParsing="false" onAction="#handlePlayAction" prefHeight="22.0" prefWidth="34.0" text="Play">
<font>
<Font size="10.0" />
</font>
</Button>
</children>
</AnchorPane>
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<Label layoutX="32.0" layoutY="50.0" text="Now Play :" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#ffffff00" height="64.0" layoutX="8.0" layoutY="27.0" stroke="BLACK" strokeType="INSIDE" width="567.0" />
<Button fx:id="show" layoutX="367.0" layoutY="46.0" mnemonicParsing="false" onAction="#openPlaylistWindow" prefHeight="26.0" prefWidth="190.0" text="Show PlayList" />
<Label fx:id="nowPlayingLabel" alignment="CENTER" layoutX="99.0" layoutY="51.0" prefHeight="18.0" prefWidth="126.0" text="Now" />
</children>
</AnchorPane>
</children>
</HBox>
<HBox prefHeight="110.0" prefWidth="578.0">
<children>
<AnchorPane prefHeight="102.0" prefWidth="578.0">
<children>
<Label fx:id="timeLabel" layoutX="142.0" layoutY="59.0" prefHeight="18.0" prefWidth="42.0" text="t" />
<Label layoutX="30.0" layoutY="59.0" prefHeight="18.0" prefWidth="42.0" text="Time" />
<Label layoutX="243.0" layoutY="40.0" prefHeight="18.0" prefWidth="49.0" text="Volume" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#e1e2e300" height="100.0" layoutX="7.0" stroke="BLACK" strokeType="INSIDE" width="567.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#e6eaed00" height="74.0" layoutX="11.0" layoutY="12.0" stroke="BLACK" strokeType="INSIDE" width="190.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#ffffff00" height="74.0" layoutX="205.0" layoutY="12.0" stroke="BLACK" strokeType="INSIDE" width="126.0" />
<ToggleButton fx:id="themeButton" layoutX="365.0" layoutY="36.0" mnemonicParsing="false" onAction="#toggleTheme" prefHeight="26.0" prefWidth="190.0" text="Change Theme" />
<Slider fx:id="timeSlider" layoutX="28.0" layoutY="42.0" prefHeight="14.0" prefWidth="156.0" />
<Slider fx:id="volumeSlider" layoutX="215.0" layoutY="19.0" orientation="VERTICAL" prefHeight="58.0" prefWidth="14.0" />
</children>
</AnchorPane>
</children>
</HBox>
</children>
</VBox>
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox
xmlns="http://javafx.com/javafx/26"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="sbu.javafx.MusicController"
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" >
<children>
<Label alignment="CENTER" prefHeight="83.0" prefWidth="600.0" text="Play List">
<font>
<Font name="B Davat" size="31.0" />
</font>
</Label>
<HBox prefHeight="342.0" prefWidth="600.0">
<children>
<AnchorPane prefHeight="271.0" prefWidth="600.0">
<children>
<ListView fx:id="playlistview" layoutX="200.0" layoutY="9.0" prefHeight="298.0" prefWidth="200.0" />
</children>
</AnchorPane>
</children>
</HBox>
</children>
</VBox>
@@ -0,0 +1,20 @@
.root {
-fx-background-color: #1e1e1e;
}
.label {
-fx-text-fill: white;
}
.button {
-fx-background-color: #333333;
-fx-text-fill: white;
}
.list-view {
-fx-background-color: #2b2b2b;
}
.slider {
-fx-control-inner-background: #333333;
}