Develop #1
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user