8 Commits
Author SHA1 Message Date
HadiSharifi 53d6e05e76 add label for current playnig 2026-05-30 02:03:05 +03:30
HadiSharifi de29e25bfd add label for current playnig 2026-05-28 12:35:13 +03:30
HadiSharifi 7c5e16de61 add methods to controller 2026-05-28 12:10:04 +03:30
HadiSharifi 21a2e95cd7 add musics folder 2026-05-28 12:09:09 +03:30
HadiSharifi b85b875249 add show/add playlist button 2026-05-28 12:08:34 +03:30
HadiSharifi 7f647d4073 add Song class 2026-05-28 11:10:49 +03:30
HadiSharifi 65b7bff1f2 implement App-view.fxml 2026-05-24 11:29:51 +03:30
HadiSharifi 19430799c6 add song class 2026-05-24 09:35:27 +03:30
10 changed files with 142 additions and 20 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>
View File
View File
View File
+2 -2
View File
@@ -45,8 +45,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version> <version>3.13.0</version>
<configuration> <configuration>
<source>23</source> <source>21</source>
<target>23</target> <target>21</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
+3 -2
View File
@@ -2,7 +2,8 @@ package sbu.javafx;
import javafx.application.Application; 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, args);
}
} }
-1
View File
@@ -16,7 +16,6 @@ public class MusicApp extends Application {
Scene scene = new Scene(fxmlLoader.load()); Scene scene = new Scene(fxmlLoader.load());
stage.setTitle("Music Player"); stage.setTitle("Music Player");
stage.setScene(scene); stage.setScene(scene);
//TODO: add icon to the stage
stage.show(); stage.show();
} }
+69 -9
View File
@@ -1,31 +1,91 @@
package sbu.javafx; package sbu.javafx;
import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import java.io.File;
public class MusicController { public class MusicController {
// TODO: Define your UI components using the @FXML annotation. @FXML Button playButton;
private boolean isPlaying = false;
@FXML private Label currentplaying;
@FXML private ListView<Song> musicListView;
private ObservableList<Song> musicList = FXCollections.observableArrayList();
private ObservableList<Song> playList = FXCollections.observableArrayList();
//TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. @FXML
public void initialize() {
File folder = new File("musics");
for (File file : folder.listFiles()) {
if (file.getName().endsWith(".mp3")) {
String[] str = file.getName().split("-");
String songName = str[0];
String artist = str[1];
musicList.add(new Song(songName,artist,file.getAbsolutePath()));
}
}
musicListView.setItems(musicList);
}
@FXML @FXML
public void handlePlayAction() { public void handlePlayAction() {
//Update labels, change button icons, etc. if (musicListView.getSelectionModel().getSelectedItem() != null) {
if (isPlaying) {
isPlaying = false;
playButton.setText("play");
currentplaying.setText("");
} else {
isPlaying = true;
playButton.setText("playing");
currentplaying.setText("Now playing: " + musicListView.getSelectionModel().getSelectedItem().getSongName());
}
}
} }
//TODO: Logic to add a specific song to the user's playlist. @FXML
public void handlePrevious() {
public void addToPlaylist(String songName) { int currentIndex = musicListView.getSelectionModel().getSelectedIndex();
//Add the song to a list or update a ListView. if (currentIndex > 0) {
musicListView.getSelectionModel().select(currentIndex - 1);
isPlaying = false;
handlePlayAction();
}
} }
// TODO:This method should open a new window or change the current scene to display the "Playlist" page. @FXML
public void handlenext() {
int currentIndex = musicListView.getSelectionModel().getSelectedIndex();
if (currentIndex < musicListView.getItems().size() - 1) {
musicListView.getSelectionModel().select(currentIndex + 1);
isPlaying = false;
handlePlayAction();
}
}
@FXML
public void addToPlaylist() {
Song song = musicListView.getSelectionModel().getSelectedItem();
if (song != null && !playList.contains(song)) {
playList.add(song);
}
}
@FXML
public void openPlaylistWindow() { public void openPlaylistWindow() {
//Create a new stage and show the playlist UI. musicListView.setItems(playList);
}
@FXML
public void openAllSongs() {
musicListView.setItems(musicList);
} }
} }
+31
View File
@@ -0,0 +1,31 @@
package sbu.javafx;
public class Song {
private String songName;
private String artist;
private String songAddress;
public Song(String songName, String artist, String songAddress) {
this.songName = songName;
this.artist = artist;
this.songAddress = songAddress;
}
public String getSongName() {
return songName;
}
public String getArtist() {
return artist;
}
public String getSongAddress() {
return songAddress;
}
@Override
public String toString() {
String result = getSongName() + " by " + getArtist();
return result;
}
}
+30 -5
View File
@@ -1,8 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10"> <?import javafx.scene.control.ListView?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<BorderPane
xmlns:fx="http//javafx.com/fxml"
fx:controller="sbu.javafx.MusicController">
<center>
<ListView fx:id="musicListView">
<padding>
<Insets top="10" right="10" bottom="10" left="10"/>
</padding>
</ListView>
</center>
<!-- TODO: Add your code here! --> <bottom>
<VBox spacing="10" alignment="CENTER">
<Label fx:id="currentplaying" text=" "/>
<HBox spacing="10" alignment="CENTER">
<Button text="Previous" onAction="#handlePrevious"/>
<Button fx:id="playButton" text="Play" onAction="#handlePlayAction"/>
<Button text="Next" onAction="#handlenext"/>
<Button text="add to playlist" onAction="#addToPlaylist"/>
<Button text="show playList" onAction="#openPlaylistWindow"/>
<Button text="show all songs" onAction="#openAllSongs"/>
</HBox>
</VBox>
</bottom>
</BorderPane>
</VBox>