Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dbd964d7a | ||
|
|
5cdd18ca50 |
Generated
+7
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -58,7 +58,8 @@
|
|||||||
<!-- Default configuration for running with: mvn clean javafx:run -->
|
<!-- Default configuration for running with: mvn clean javafx:run -->
|
||||||
<id>default-cli</id>
|
<id>default-cli</id>
|
||||||
<configuration>
|
<configuration>
|
||||||
<mainClass>sbu.javafx/sbu.javafx.MusicApp</mainClass>
|
<!-- Use the Launcher class (contains the main entry point). Remove modular-style value. -->
|
||||||
|
<mainClass>sbu.javafx.Launcher</mainClass>
|
||||||
<launcher>app</launcher>
|
<launcher>app</launcher>
|
||||||
<jlinkZipName>app</jlinkZipName>
|
<jlinkZipName>app</jlinkZipName>
|
||||||
<jlinkImageName>app</jlinkImageName>
|
<jlinkImageName>app</jlinkImageName>
|
||||||
|
|||||||
@@ -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,31 +1,79 @@
|
|||||||
package sbu.javafx;
|
package sbu.javafx;
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
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.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class MusicController {
|
public class MusicController {
|
||||||
|
|
||||||
// TODO: Define your UI components using the @FXML annotation.
|
@FXML private Label nowPlayingLabel;
|
||||||
|
|
||||||
//TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing.
|
@FXML private Button playBtn1;
|
||||||
|
@FXML private Button playBtn2;
|
||||||
|
@FXML private Button playBtn3;
|
||||||
|
|
||||||
|
private final ArrayList<String> playlist = new ArrayList<>();
|
||||||
|
private Button currentlyPlayingBtn;
|
||||||
|
private Scene mainScene;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void handlePlayAction() {
|
public void handlePlayAction(ActionEvent event) {
|
||||||
//Update labels, change button icons, etc.
|
Button clicked = (Button) event.getSource();
|
||||||
}
|
String song = (String) clicked.getUserData();
|
||||||
|
|
||||||
//TODO: Logic to add a specific song to the user's playlist.
|
// Visual feedback: reset previous button, mark new one
|
||||||
|
if (currentlyPlayingBtn != null) {
|
||||||
|
currentlyPlayingBtn.setText("Play");
|
||||||
|
}
|
||||||
|
clicked.setText("Playing");
|
||||||
|
currentlyPlayingBtn = clicked;
|
||||||
|
|
||||||
|
nowPlayingLabel.setText("Now Playing: " + song);
|
||||||
|
}
|
||||||
|
|
||||||
public void addToPlaylist(String songName) {
|
public void addToPlaylist(String songName) {
|
||||||
//Add the song to a list or update a ListView.
|
if (!playlist.contains(songName)) {
|
||||||
|
playlist.add(songName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:This method should open a new window or change the current scene to display the "Playlist" page.
|
@FXML
|
||||||
|
public void handleAddToPlaylist(ActionEvent event) {
|
||||||
|
Button clicked = (Button) event.getSource();
|
||||||
|
String song = (String) clicked.getUserData();
|
||||||
|
addToPlaylist(song);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
public void openPlaylistWindow() {
|
public void openPlaylistWindow() {
|
||||||
//Create a new stage and show the playlist UI.
|
Stage stage = (Stage) nowPlayingLabel.getScene().getWindow();
|
||||||
|
mainScene = stage.getScene();
|
||||||
|
|
||||||
|
Label title = new Label("Your Playlist");
|
||||||
|
title.setStyle("-fx-font-size: 20; -fx-font-weight: bold;");
|
||||||
|
|
||||||
|
ListView<String> listView = new ListView<>(
|
||||||
|
FXCollections.observableArrayList(playlist)
|
||||||
|
);
|
||||||
|
listView.setPrefHeight(200);
|
||||||
|
|
||||||
|
Button backButton = new Button("Back to Player");
|
||||||
|
backButton.setOnAction(e -> stage.setScene(mainScene));
|
||||||
|
|
||||||
|
VBox layout = new VBox(15, title, listView, backButton);
|
||||||
|
layout.setPadding(new Insets(25));
|
||||||
|
layout.setAlignment(Pos.CENTER);
|
||||||
|
|
||||||
|
stage.setScene(new Scene(layout, 400, 350));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.scene.layout.GridPane?>
|
||||||
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Separator?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
|
||||||
<!-- TODO: Add your code here! -->
|
<VBox xmlns="http://javafx.com/fxml"
|
||||||
|
xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="sbu.javafx.MusicController"
|
||||||
|
alignment="CENTER"
|
||||||
|
spacing="15"
|
||||||
|
prefWidth="580"
|
||||||
|
prefHeight="380">
|
||||||
|
<padding>
|
||||||
|
<Insets top="25" right="25" bottom="25" left="25"/>
|
||||||
|
</padding>
|
||||||
|
|
||||||
|
<Label text="Music Player" style="-fx-font-size: 26; -fx-font-weight: bold;"/>
|
||||||
|
|
||||||
|
<Label fx:id="nowPlayingLabel" text="Now Playing: —"
|
||||||
|
style="-fx-font-size: 13; -fx-text-fill: #666666;"/>
|
||||||
|
|
||||||
|
<Separator/>
|
||||||
|
|
||||||
|
<GridPane hgap="12" vgap="10" alignment="CENTER">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints minWidth="170" prefWidth="170"/>
|
||||||
|
<ColumnConstraints minWidth="120" prefWidth="120"/>
|
||||||
|
<ColumnConstraints minWidth="60" prefWidth="60"/>
|
||||||
|
<ColumnConstraints minWidth="80" prefWidth="80"/>
|
||||||
|
<ColumnConstraints minWidth="110" prefWidth="110"/>
|
||||||
|
</columnConstraints>
|
||||||
|
|
||||||
|
<!-- Header row -->
|
||||||
|
<Label text="Title" style="-fx-font-weight: bold;" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
|
||||||
|
<Label text="Artist" style="-fx-font-weight: bold;" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
|
||||||
|
<Label text="Duration" style="-fx-font-weight: bold;" GridPane.columnIndex="2" GridPane.rowIndex="0"/>
|
||||||
|
|
||||||
|
<!-- Song 1: Blinding Lights -->
|
||||||
|
<Label text="Blinding Lights" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
|
||||||
|
<Label text="The Weeknd" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
|
||||||
|
<Label text="3:20" GridPane.columnIndex="2" GridPane.rowIndex="1"/>
|
||||||
|
<Button fx:id="playBtn1" text="Play" userData="Blinding Lights"
|
||||||
|
onAction="#handlePlayAction"
|
||||||
|
GridPane.columnIndex="3" GridPane.rowIndex="1"/>
|
||||||
|
<Button text="+ Playlist" userData="Blinding Lights"
|
||||||
|
onAction="#handleAddToPlaylist"
|
||||||
|
GridPane.columnIndex="4" GridPane.rowIndex="1"/>
|
||||||
|
|
||||||
|
<!-- Song 2: Shape of You -->
|
||||||
|
<Label text="Shape of You" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
|
||||||
|
<Label text="Ed Sheeran" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
|
||||||
|
<Label text="3:53" GridPane.columnIndex="2" GridPane.rowIndex="2"/>
|
||||||
|
<Button fx:id="playBtn2" text="Play" userData="Shape of You"
|
||||||
|
onAction="#handlePlayAction"
|
||||||
|
GridPane.columnIndex="3" GridPane.rowIndex="2"/>
|
||||||
|
<Button text="+ Playlist" userData="Shape of You"
|
||||||
|
onAction="#handleAddToPlaylist"
|
||||||
|
GridPane.columnIndex="4" GridPane.rowIndex="2"/>
|
||||||
|
|
||||||
|
<!-- Song 3: Levitating -->
|
||||||
|
<Label text="Levitating" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
|
||||||
|
<Label text="Dua Lipa" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
|
||||||
|
<Label text="3:23" GridPane.columnIndex="2" GridPane.rowIndex="3"/>
|
||||||
|
<Button fx:id="playBtn3" text="Play" userData="Levitating"
|
||||||
|
onAction="#handlePlayAction"
|
||||||
|
GridPane.columnIndex="3" GridPane.rowIndex="3"/>
|
||||||
|
<Button text="+ Playlist" userData="Levitating"
|
||||||
|
onAction="#handleAddToPlaylist"
|
||||||
|
GridPane.columnIndex="4" GridPane.rowIndex="3"/>
|
||||||
|
</GridPane>
|
||||||
|
|
||||||
|
<Separator/>
|
||||||
|
|
||||||
|
<Button text="View Playlist" onAction="#openPlaylistWindow"
|
||||||
|
style="-fx-font-size: 13; -fx-padding: 6 20 6 20;"/>
|
||||||
</VBox>
|
</VBox>
|
||||||
|
|||||||
Reference in New Issue
Block a user