trying to make a playlist of Adele's songs #3

Closed
avasanatkar wants to merge 1 commits from avasanatkar/HW-7:develop into main
7 changed files with 208 additions and 8 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>
+2
View File
@@ -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);
}
} }
+40 -4
View File
@@ -1,31 +1,67 @@
package sbu.javafx; package sbu.javafx;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.event.ActionEvent;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox; import java.io.IOException;
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;
//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.
private ArrayList<String> playlist = new ArrayList<>();
private ObservableList<String> observablePlaylist = FXCollections.observableArrayList(playlist);
@FXML @FXML
public void handlePlayAction() { public void handlePlayAction() {
//Update labels, change button icons, etc. //Update labels, change button icons, etc.
} }
@FXML public void playSong0() { nowPlayingLabel.setText("♪ Now Playing: Hello — Adele"); }
@FXML public void playSong1() { nowPlayingLabel.setText("♪ Now Playing: Someone Like You — Adele"); }
@FXML public void playSong2() { nowPlayingLabel.setText("♪ Now Playing: Rolling in the Deep — Adele"); }
@FXML public void playSong3() { nowPlayingLabel.setText("♪ Now Playing: Easy On Me — Adele"); }
@FXML public void playSong4() { nowPlayingLabel.setText("♪ Now Playing: Set Fire to the Rain — Adele"); }
@FXML public void playSong5() { nowPlayingLabel.setText("♪ Now Playing: Skyfall — Adele"); }
//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 (!observablePlaylist.contains(songName)) {
observablePlaylist.add(songName);
}
} }
@FXML public void addSong0() { addToPlaylist("Hello · Adele · 4:55"); }
@FXML public void addSong1() { addToPlaylist("Someone Like You · Adele · 4:45"); }
@FXML public void addSong2() { addToPlaylist("Rolling in the Deep · Adele · 3:48"); }
@FXML public void addSong3() { addToPlaylist("Easy On Me · Adele · 3:44"); }
@FXML public void addSong4() { addToPlaylist("Set Fire to the Rain · Adele · 4:01"); }
@FXML public void addSong5() { addToPlaylist("Skyfall · Adele · 4:46"); }
// 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. //Create a new stage and show the playlist UI.
} }
@FXML
public void viewPlaylist() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Playlist-view.fxml"));
Parent root = loader.load();
PlaylistController pc = loader.getController();
pc.setPlaylist(observablePlaylist);
Stage stage = (Stage) nowPlayingLabel.getScene().getWindow();
stage.setScene(new Scene(root));
}
} }
@@ -0,0 +1,29 @@
package sbu.javafx;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.stage.Stage;
import java.io.IOException;
public class PlaylistController {
@FXML
private ListView<String> playlistView;
public void setPlaylist(ObservableList<String> items) {
playlistView.setItems(items);
}
@FXML
public void goBack() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("App-view.fxml"));
Parent root = loader.load();
Stage stage = (Stage) playlistView.getScene().getWindow();
stage.setScene(new Scene(root));
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 225 KiB

+108 -4
View File
@@ -1,8 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.control.*?>
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10"> <?import javafx.scene.layout.*?>
<?import javafx.geometry.*?>
<!-- TODO: Add your code here! --> <VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="sbu.javafx.MusicController"
spacing="0">
</VBox> <!-- Header -->
<HBox alignment="CENTER_LEFT" spacing="12" style="-fx-background-color: #1a1a2e; -fx-padding: 18 28 18 28;">
<Label text="♪ Music Player" style="-fx-text-fill: white; -fx-font-size: 20px; -fx-font-weight: bold;"/>
<Region HBox.hgrow="ALWAYS"/>
<Button text="☰ View Playlist" onAction="#viewPlaylist"
style="-fx-background-color: transparent; -fx-text-fill: #cccccc; -fx-border-color: #555; -fx-border-radius: 6; -fx-padding: 7 16 7 16; -fx-cursor: hand;"/>
</HBox>
<!-- Now Playing -->
<HBox alignment="CENTER_LEFT" style="-fx-background-color: #1e1e3a; -fx-padding: 10 28 10 28; -fx-border-color: #7c6af7; -fx-border-width: 0 0 2 0;">
<Label fx:id="nowPlayingLabel" text="Select a song to start playing …"
style="-fx-text-fill: #b0a8ff; -fx-font-size: 13px; -fx-font-style: italic;"/>
</HBox>
<!-- Column Headers -->
<HBox alignment="CENTER_LEFT" style="-fx-background-color: #1a1a1a; -fx-padding: 8 28 8 28;">
<Label text="#" style="-fx-text-fill: #666; -fx-font-size: 11px; -fx-font-weight: bold;" minWidth="32"/>
<Label text="TITLE" style="-fx-text-fill: #666; -fx-font-size: 11px; -fx-font-weight: bold;" HBox.hgrow="ALWAYS"/>
<Label text="ARTIST" style="-fx-text-fill: #666; -fx-font-size: 11px; -fx-font-weight: bold;" minWidth="150"/>
<Label text="TIME" style="-fx-text-fill: #666; -fx-font-size: 11px; -fx-font-weight: bold;" minWidth="70"/>
<Label text="" minWidth="210"/>
</HBox>
<!-- Song 1 - Hello -->
<HBox alignment="CENTER_LEFT" minHeight="62" style="-fx-background-color: #121212; -fx-padding: 0 28 0 28; -fx-border-color: #1e1e1e; -fx-border-width: 0 0 1 0;">
<Label text="1" style="-fx-text-fill: #444;" minWidth="32"/>
<Label text="Hello" style="-fx-text-fill: #e8e8e8; -fx-font-weight: bold;" HBox.hgrow="ALWAYS"/>
<Label text="Adele" style="-fx-text-fill: #999;" minWidth="150"/>
<Label text="4:55" style="-fx-text-fill: #777;" minWidth="70"/>
<HBox spacing="8" alignment="CENTER_RIGHT" minWidth="210">
<Button text="▶ Play" onAction="#playSong0" style="-fx-background-color: #7c6af7; -fx-text-fill: white; -fx-font-weight: bold; -fx-background-radius: 20; -fx-padding: 7 16 7 16; -fx-cursor: hand;"/>
<Button text=" Add" onAction="#addSong0" style="-fx-background-color: transparent; -fx-text-fill: #7c6af7; -fx-border-color: #7c6af7; -fx-border-radius: 20; -fx-border-width: 1.5; -fx-padding: 6 14 6 14; -fx-cursor: hand;"/>
</HBox>
</HBox>
<!-- Song 2 - Someone Like You -->
<HBox alignment="CENTER_LEFT" minHeight="62" style="-fx-background-color: #161616; -fx-padding: 0 28 0 28; -fx-border-color: #1e1e1e; -fx-border-width: 0 0 1 0;">
<Label text="2" style="-fx-text-fill: #444;" minWidth="32"/>
<Label text="Someone Like You" style="-fx-text-fill: #e8e8e8; -fx-font-weight: bold;" HBox.hgrow="ALWAYS"/>
<Label text="Adele" style="-fx-text-fill: #999;" minWidth="150"/>
<Label text="4:45" style="-fx-text-fill: #777;" minWidth="70"/>
<HBox spacing="8" alignment="CENTER_RIGHT" minWidth="210">
<Button text="▶ Play" onAction="#playSong1" style="-fx-background-color: #7c6af7; -fx-text-fill: white; -fx-font-weight: bold; -fx-background-radius: 20; -fx-padding: 7 16 7 16; -fx-cursor: hand;"/>
<Button text=" Add" onAction="#addSong1" style="-fx-background-color: transparent; -fx-text-fill: #7c6af7; -fx-border-color: #7c6af7; -fx-border-radius: 20; -fx-border-width: 1.5; -fx-padding: 6 14 6 14; -fx-cursor: hand;"/>
</HBox>
</HBox>
<!-- Song 3 - Rolling in the Deep -->
<HBox alignment="CENTER_LEFT" minHeight="62" style="-fx-background-color: #121212; -fx-padding: 0 28 0 28; -fx-border-color: #1e1e1e; -fx-border-width: 0 0 1 0;">
<Label text="3" style="-fx-text-fill: #444;" minWidth="32"/>
<Label text="Rolling in the Deep" style="-fx-text-fill: #e8e8e8; -fx-font-weight: bold;" HBox.hgrow="ALWAYS"/>
<Label text="Adele" style="-fx-text-fill: #999;" minWidth="150"/>
<Label text="3:48" style="-fx-text-fill: #777;" minWidth="70"/>
<HBox spacing="8" alignment="CENTER_RIGHT" minWidth="210">
<Button text="▶ Play" onAction="#playSong2" style="-fx-background-color: #7c6af7; -fx-text-fill: white; -fx-font-weight: bold; -fx-background-radius: 20; -fx-padding: 7 16 7 16; -fx-cursor: hand;"/>
<Button text=" Add" onAction="#addSong2" style="-fx-background-color: transparent; -fx-text-fill: #7c6af7; -fx-border-color: #7c6af7; -fx-border-radius: 20; -fx-border-width: 1.5; -fx-padding: 6 14 6 14; -fx-cursor: hand;"/>
</HBox>
</HBox>
<!-- Song 4 - Easy On Me -->
<HBox alignment="CENTER_LEFT" minHeight="62" style="-fx-background-color: #161616; -fx-padding: 0 28 0 28; -fx-border-color: #1e1e1e; -fx-border-width: 0 0 1 0;">
<Label text="4" style="-fx-text-fill: #444;" minWidth="32"/>
<Label text="Easy On Me" style="-fx-text-fill: #e8e8e8; -fx-font-weight: bold;" HBox.hgrow="ALWAYS"/>
<Label text="Adele" style="-fx-text-fill: #999;" minWidth="150"/>
<Label text="3:44" style="-fx-text-fill: #777;" minWidth="70"/>
<HBox spacing="8" alignment="CENTER_RIGHT" minWidth="210">
<Button text="▶ Play" onAction="#playSong3" style="-fx-background-color: #7c6af7; -fx-text-fill: white; -fx-font-weight: bold; -fx-background-radius: 20; -fx-padding: 7 16 7 16; -fx-cursor: hand;"/>
<Button text=" Add" onAction="#addSong3" style="-fx-background-color: transparent; -fx-text-fill: #7c6af7; -fx-border-color: #7c6af7; -fx-border-radius: 20; -fx-border-width: 1.5; -fx-padding: 6 14 6 14; -fx-cursor: hand;"/>
</HBox>
</HBox>
<!-- Song 5 - Set Fire to the Rain -->
<HBox alignment="CENTER_LEFT" minHeight="62" style="-fx-background-color: #121212; -fx-padding: 0 28 0 28; -fx-border-color: #1e1e1e; -fx-border-width: 0 0 1 0;">
<Label text="5" style="-fx-text-fill: #444;" minWidth="32"/>
<Label text="Set Fire to the Rain" style="-fx-text-fill: #e8e8e8; -fx-font-weight: bold;" HBox.hgrow="ALWAYS"/>
<Label text="Adele" style="-fx-text-fill: #999;" minWidth="150"/>
<Label text="4:01" style="-fx-text-fill: #777;" minWidth="70"/>
<HBox spacing="8" alignment="CENTER_RIGHT" minWidth="210">
<Button text="▶ Play" onAction="#playSong4" style="-fx-background-color: #7c6af7; -fx-text-fill: white; -fx-font-weight: bold; -fx-background-radius: 20; -fx-padding: 7 16 7 16; -fx-cursor: hand;"/>
<Button text=" Add" onAction="#addSong4" style="-fx-background-color: transparent; -fx-text-fill: #7c6af7; -fx-border-color: #7c6af7; -fx-border-radius: 20; -fx-border-width: 1.5; -fx-padding: 6 14 6 14; -fx-cursor: hand;"/>
</HBox>
</HBox>
<!-- Song 6 - Skyfall -->
<HBox alignment="CENTER_LEFT" minHeight="62" style="-fx-background-color: #161616; -fx-padding: 0 28 0 28; -fx-border-color: #1e1e1e; -fx-border-width: 0 0 1 0;">
<Label text="6" style="-fx-text-fill: #444;" minWidth="32"/>
<Label text="Skyfall" style="-fx-text-fill: #e8e8e8; -fx-font-weight: bold;" HBox.hgrow="ALWAYS"/>
<Label text="Adele" style="-fx-text-fill: #999;" minWidth="150"/>
<Label text="4:46" style="-fx-text-fill: #777;" minWidth="70"/>
<HBox spacing="8" alignment="CENTER_RIGHT" minWidth="210">
<Button text="▶ Play" onAction="#playSong5" style="-fx-background-color: #7c6af7; -fx-text-fill: white; -fx-font-weight: bold; -fx-background-radius: 20; -fx-padding: 7 16 7 16; -fx-cursor: hand;"/>
<Button text=" Add" onAction="#addSong5" style="-fx-background-color: transparent; -fx-text-fill: #7c6af7; -fx-border-color: #7c6af7; -fx-border-radius: 20; -fx-border-width: 1.5; -fx-padding: 6 14 6 14; -fx-cursor: hand;"/>
</HBox>
</HBox>
<!-- Footer -->
<HBox alignment="CENTER" style="-fx-background-color: #0e0e0e; -fx-padding: 12; -fx-border-color: #1e1e1e; -fx-border-width: 1 0 0 0;">
<Label text="HW-7 · JavaFX Music Player · SBU" style="-fx-text-fill: #444; -fx-font-size: 11px;"/>
</HBox>
</VBox>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.*?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="sbu.javafx.PlaylistController"
spacing="10">
<padding><Insets top="20" right="20" bottom="20" left="20"/></padding>
<Label text="My Playlist"
style="-fx-font-size: 20px; -fx-font-weight: bold;"/>
<ListView fx:id="playlistView" VBox.vgrow="ALWAYS"
style="-fx-pref-height: 400;"/>
<Button text="← Back to Player" onAction="#goBack"
style="-fx-padding: 8 20 8 20; -fx-cursor: hand;"/>
</VBox>