Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
342c88609e | ||
|
|
7f0c09d9bf |
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>
|
||||||
@@ -2,7 +2,9 @@ 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) }
|
// TODO: Launch the JavaFX application by calling Application.launch(Main.class)
|
||||||
|
Application.launch(MusicApp.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class MusicApp extends Application {
|
|||||||
public void start(Stage stage) throws IOException
|
public void start(Stage stage) throws IOException
|
||||||
{
|
{
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
|
||||||
Scene scene = new Scene(fxmlLoader.load());
|
Scene scene = new Scene(fxmlLoader.load(), 800, 800);
|
||||||
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
|
||||||
|
|||||||
@@ -1,31 +1,65 @@
|
|||||||
package sbu.javafx;
|
package sbu.javafx;
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
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 java.util.ArrayList;
|
||||||
|
|
||||||
public class MusicController {
|
public class MusicController {
|
||||||
|
@FXML
|
||||||
|
private Label nowPlayingLabel;
|
||||||
|
private ArrayList<String> playlist= new ArrayList<>();
|
||||||
// TODO: Define your UI components using the @FXML annotation.
|
// 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.
|
//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 playSummertime() {
|
||||||
|
nowPlayingLabel.setText("Now Playing: Summertime Sadness");
|
||||||
//Update labels, change button icons, etc.
|
//Update labels, change button icons, etc.
|
||||||
}
|
}
|
||||||
|
public void playSpaghetti() {
|
||||||
|
nowPlayingLabel.setText("Now Playing: Spaghetti");
|
||||||
|
}
|
||||||
|
public void playBadShodam() {
|
||||||
|
nowPlayingLabel.setText("Now Playing: Bad Shodam");
|
||||||
|
}
|
||||||
|
|
||||||
//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 addSummertime() {
|
||||||
//Add the song to a list or update a ListView.
|
playlist.add("Summertime Sadness");
|
||||||
|
}
|
||||||
|
public void addSpaghetti() {
|
||||||
|
playlist.add("Spaghetti");
|
||||||
|
}
|
||||||
|
public void addBadShodam() {
|
||||||
|
playlist.add("Bad Shodam");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
|
||||||
public void openPlaylistWindow() {
|
public void openPlaylistWindow() {
|
||||||
//Create a new stage and show the playlist UI.
|
Stage playlistStage = new Stage();
|
||||||
|
playlistStage.setTitle("My Playlist");
|
||||||
|
|
||||||
|
ListView<String> listView = new ListView<>();
|
||||||
|
|
||||||
|
listView.getItems().addAll(playlist);
|
||||||
|
|
||||||
|
if (playlist.isEmpty()) {
|
||||||
|
listView.setPlaceholder(new Label("Your playlist is empty!"));
|
||||||
|
}
|
||||||
|
VBox layout = new VBox(listView);
|
||||||
|
Scene scene = new Scene(layout, 300, 400);
|
||||||
|
|
||||||
|
playlistStage.setScene(scene);
|
||||||
|
playlistStage.show(); }
|
||||||
|
|
||||||
|
public void playSong() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,96 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.geometry.Insets?>
|
||||||
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import java.net.URL?>
|
||||||
|
|
||||||
<!-- TODO: Add your code here! -->
|
<VBox alignment="TOP_CENTER" spacing="20.0" styleClass="root-container" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sbu.javafx.MusicController">
|
||||||
|
|
||||||
|
<stylesheets>
|
||||||
|
<URL value="@style.css" />
|
||||||
|
</stylesheets>
|
||||||
|
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
||||||
|
</padding>
|
||||||
|
|
||||||
|
<Label text="Music Player" style="-fx-font-size: 32px; -fx-font-weight: bold;" />
|
||||||
|
|
||||||
|
<VBox styleClass="music-table">
|
||||||
|
|
||||||
|
<GridPane hgap="10" styleClass="table-header">
|
||||||
|
<padding><Insets bottom="10" left="10" right="10" top="10" /></padding>
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="150" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="150" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="80" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="120" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="80" />
|
||||||
|
</columnConstraints>
|
||||||
|
<Label styleClass="header-label" text="Song Title" GridPane.columnIndex="0" />
|
||||||
|
<Label styleClass="header-label" text="Artist Name" GridPane.columnIndex="1" />
|
||||||
|
<Label styleClass="header-label" text="Duration" GridPane.columnIndex="2" />
|
||||||
|
<Label styleClass="header-label" text="Add to Playlist" GridPane.columnIndex="3" alignment="CENTER" prefWidth="120"/>
|
||||||
|
<Label styleClass="header-label" text="Play" GridPane.columnIndex="4" alignment="CENTER" prefWidth="80"/>
|
||||||
|
</GridPane>
|
||||||
|
|
||||||
|
<GridPane hgap="10" styleClass="table-row">
|
||||||
|
<padding><Insets bottom="15" left="10" right="10" top="15" /></padding>
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="150" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="150" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="80" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="120" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="80" />
|
||||||
|
</columnConstraints>
|
||||||
|
<Label text="Summertime Sadness" GridPane.columnIndex="0" />
|
||||||
|
<Label text="Lana Del Rey" GridPane.columnIndex="1" />
|
||||||
|
<Label text="04:24" GridPane.columnIndex="2" />
|
||||||
|
<Button text="Add to Playlist" GridPane.columnIndex="3" GridPane.halignment="CENTER" onAction="#addSummertime" />
|
||||||
|
<Button text="Play" prefWidth="60" GridPane.columnIndex="4" GridPane.halignment="CENTER" onAction="#playSummertime" />
|
||||||
|
</GridPane>
|
||||||
|
|
||||||
|
<GridPane hgap="10" styleClass="table-row">
|
||||||
|
<padding><Insets bottom="15" left="10" right="10" top="15" /></padding>
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="150" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="150" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="80" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="120" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="80" />
|
||||||
|
</columnConstraints>
|
||||||
|
<Label text="Spaghetti" GridPane.columnIndex="0" />
|
||||||
|
<Label text="City of the Sun" GridPane.columnIndex="1" />
|
||||||
|
<Label text="05:14" GridPane.columnIndex="2" />
|
||||||
|
<Button text="Add to Playlist" GridPane.columnIndex="3" GridPane.halignment="CENTER" onAction="#addSpaghetti" />
|
||||||
|
<Button text="Play" prefWidth="60" GridPane.columnIndex="4" GridPane.halignment="CENTER" onAction="#playSpaghetti" />
|
||||||
|
</GridPane>
|
||||||
|
|
||||||
|
<GridPane hgap="10" styleClass="no-border">
|
||||||
|
<padding><Insets bottom="15" left="10" right="10" top="15" /></padding>
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="150" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="150" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="80" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="120" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="80" />
|
||||||
|
</columnConstraints>
|
||||||
|
<Label text="Bad Shodam" GridPane.columnIndex="0" />
|
||||||
|
<Label text="Yas" GridPane.columnIndex="1" />
|
||||||
|
<Label text="05:34" GridPane.columnIndex="2" />
|
||||||
|
<Button text="Add to Playlist" GridPane.columnIndex="3" GridPane.halignment="CENTER" onAction="#addBadShodam" />
|
||||||
|
<Button text="Play" prefWidth="60" GridPane.columnIndex="4" GridPane.halignment="CENTER" onAction="#playBadShodam" />
|
||||||
|
</GridPane>
|
||||||
|
|
||||||
|
</VBox>
|
||||||
|
|
||||||
|
<Region VBox.vgrow="ALWAYS" />
|
||||||
|
|
||||||
|
<HBox alignment="CENTER_LEFT" spacing="20" styleClass="footer-bar">
|
||||||
|
<padding><Insets bottom="20" left="20" right="20" top="20" /></padding>
|
||||||
|
<Label fx:id="nowPlayingLabel" text="Now Playing: -" />
|
||||||
|
<Region HBox.hgrow="ALWAYS" />
|
||||||
|
<Button text="Open Playlist" onAction="#openPlaylistWindow" prefHeight="40" prefWidth="150" />
|
||||||
|
</HBox>
|
||||||
</VBox>
|
</VBox>
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/* The main container */
|
||||||
|
.root-container {
|
||||||
|
-fx-background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The box containing the table */
|
||||||
|
.music-table {
|
||||||
|
-fx-border-color: black;
|
||||||
|
-fx-border-width: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The header row */
|
||||||
|
.table-header {
|
||||||
|
-fx-background-color: #f4f4f4;
|
||||||
|
-fx-border-color: black;
|
||||||
|
-fx-border-width: 0 0 1 0; /* Border only at the bottom */
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-label {
|
||||||
|
-fx-font-weight: bold;
|
||||||
|
-fx-font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Individual song rows */
|
||||||
|
.table-row {
|
||||||
|
-fx-border-color: black;
|
||||||
|
-fx-border-width: 0 0 1 0; /* Border only at the bottom */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The last row shouldn't have a bottom border inside the box */
|
||||||
|
.no-border {
|
||||||
|
-fx-border-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The bottom "Now Playing" bar */
|
||||||
|
.footer-bar {
|
||||||
|
-fx-border-color: black;
|
||||||
|
-fx-border-width: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Buttons */
|
||||||
|
.button {
|
||||||
|
-fx-background-color: white;
|
||||||
|
-fx-border-color: black;
|
||||||
|
-fx-cursor: hand;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover {
|
||||||
|
-fx-background-color: #eeeeee;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user