Merge pull request 'Implement JavaFX music player features 2' (#1) from dvelope into main
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
Generated
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</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_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
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>
|
||||||
@@ -5,4 +5,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) }
|
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) }
|
||||||
}
|
Application.launch(MusicApp.class, args);
|
||||||
|
|
||||||
|
}}
|
||||||
@@ -4,6 +4,7 @@ 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.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -17,6 +18,9 @@ public class MusicApp extends Application {
|
|||||||
stage.setTitle("Music Player");
|
stage.setTitle("Music Player");
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
//TODO: add icon to the stage
|
//TODO: add icon to the stage
|
||||||
|
stage.getIcons().add(
|
||||||
|
new Image(MusicApp.class.getResourceAsStream("icon.png"))
|
||||||
|
);
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,29 +3,85 @@ package sbu.javafx;
|
|||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
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 Label nowPlayingLabel;
|
||||||
|
|
||||||
|
private final ArrayList<String> playlist = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
//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.
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void handlePlayAction() {
|
public void handlePlayAction(ActionEvent event) {
|
||||||
//Update labels, change button icons, etc.
|
//Update labels, change button icons, etc.
|
||||||
}
|
Button button = (Button) event.getSource();
|
||||||
|
String songName = button.getUserData().toString();
|
||||||
|
|
||||||
|
nowPlayingLabel.setText("Now Playing : " + songName);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//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) {
|
public void addToPlaylist(String songName) {
|
||||||
//Add the song to a list or update a ListView.
|
//Add the song to a list or update a ListView.
|
||||||
|
if (!playlist.contains(songName)) {
|
||||||
|
playlist.add(songName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void addSong1() {
|
||||||
|
addToPlaylist("Shape Of You");
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void addSong2() {
|
||||||
|
addToPlaylist("Believer");
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void addSong3() {
|
||||||
|
addToPlaylist("Perfect");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
@FXML
|
||||||
public void openPlaylistWindow() {
|
public void openPlaylistWindow() {
|
||||||
//Create a new stage and show the playlist UI.
|
//Create a new stage and show the playlist UI.
|
||||||
|
Stage stage = new Stage();
|
||||||
|
|
||||||
|
VBox root = new VBox(15);
|
||||||
|
root.setPadding(new Insets(20));
|
||||||
|
|
||||||
|
Label title = new Label("My Playlist");
|
||||||
|
|
||||||
|
ListView<String> listView = new ListView<>();
|
||||||
|
listView.getItems().addAll(playlist);
|
||||||
|
|
||||||
|
Button closeButton = new Button("Close");
|
||||||
|
closeButton.setOnAction(e -> stage.close());
|
||||||
|
|
||||||
|
root.getChildren().addAll(title, listView, closeButton);
|
||||||
|
|
||||||
|
Scene scene = new Scene(root, 350, 400);
|
||||||
|
|
||||||
|
stage.setTitle("Playlist");
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,81 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<VBox xmlns="http://javafx.com/javafx/17"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="sbu.javafx.MusicController"
|
||||||
|
alignment="TOP_CENTER"
|
||||||
|
spacing="15"
|
||||||
|
prefWidth="400"
|
||||||
|
prefHeight="500">
|
||||||
|
|
||||||
<!-- TODO: Add your code here! -->
|
<padding>
|
||||||
|
<Insets top="20" right="20" bottom="20" left="20"/>
|
||||||
|
</padding>
|
||||||
|
|
||||||
|
<Label text="Music Player"
|
||||||
|
style="-fx-font-size:24px; -fx-font-weight:bold;"/>
|
||||||
|
|
||||||
|
<Label fx:id="nowPlayingLabel"
|
||||||
|
text="Now Playing : None"
|
||||||
|
style="-fx-font-size:16px;"/>
|
||||||
|
|
||||||
|
<!-- Song 1 -->
|
||||||
|
<HBox spacing="10" alignment="CENTER_LEFT">
|
||||||
|
|
||||||
|
<VBox spacing="3">
|
||||||
|
<Label text="Shape Of You"/>
|
||||||
|
<Label text="Ed Sheeran"/>
|
||||||
|
<Label text="3:55"/>
|
||||||
|
</VBox>
|
||||||
|
|
||||||
|
<Button text="Play"
|
||||||
|
onAction="#handlePlayAction"
|
||||||
|
userData="Shape Of You"/>
|
||||||
|
|
||||||
|
<Button text="Add to Playlist"
|
||||||
|
onAction="#addSong1"/>
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
<!-- Song 2 -->
|
||||||
|
<HBox spacing="10" alignment="CENTER_LEFT">
|
||||||
|
|
||||||
|
<VBox spacing="3">
|
||||||
|
<Label text="Believer"/>
|
||||||
|
<Label text="Imagine Dragons"/>
|
||||||
|
<Label text="3:24"/>
|
||||||
|
</VBox>
|
||||||
|
|
||||||
|
<Button text="Play"
|
||||||
|
onAction="#handlePlayAction"
|
||||||
|
userData="Believer"/>
|
||||||
|
|
||||||
|
<Button text="Add to Playlist"
|
||||||
|
onAction="#addSong2"/>
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
<!-- Song 3 -->
|
||||||
|
<HBox spacing="10" alignment="CENTER_LEFT">
|
||||||
|
|
||||||
|
<VBox spacing="3">
|
||||||
|
<Label text="Perfect"/>
|
||||||
|
<Label text="Ed Sheeran"/>
|
||||||
|
<Label text="4:21"/>
|
||||||
|
</VBox>
|
||||||
|
|
||||||
|
<Button text="Play"
|
||||||
|
onAction="#handlePlayAction"
|
||||||
|
userData="Perfect"/>
|
||||||
|
|
||||||
|
<Button text="Add to Playlist"
|
||||||
|
onAction="#addSong3"/>
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
<Button text="View Playlist"
|
||||||
|
onAction="#openPlaylistWindow"/>
|
||||||
|
|
||||||
</VBox>
|
</VBox>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
Reference in New Issue
Block a user