HW-07-JavaFX is complete
This commit is contained in:
Generated
+1
@@ -0,0 +1 @@
|
|||||||
|
Launcher.java
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ADDITIONAL_TAGS" value="Author" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
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>
|
||||||
@@ -2,7 +2,12 @@ package sbu.javafx;
|
|||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
|
||||||
public class Launcher{
|
/**
|
||||||
|
* @Author Hesam Ghazi
|
||||||
|
* Student Number: 403222015
|
||||||
|
*/
|
||||||
|
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,105 @@
|
|||||||
package sbu.javafx;
|
package sbu.javafx;
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.fxml.FXMLLoader;
|
||||||
|
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.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MusicController {
|
public class MusicController {
|
||||||
|
|
||||||
// TODO: Define your UI components using the @FXML annotation.
|
@FXML private VBox mainContainer;
|
||||||
|
@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.
|
// Rows and buttons for visual feedback
|
||||||
|
@FXML private HBox row1, row2, row3;
|
||||||
|
@FXML private Button playBtn1, playBtn2, playBtn3;
|
||||||
|
|
||||||
|
private static final List<String> playlist = new ArrayList<>();
|
||||||
|
private static boolean isDarkMode = false;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void handlePlayAction() {
|
public void initialize() {
|
||||||
//Update labels, change button icons, etc.
|
// Keeps theme consistent if returning back from the playlist view
|
||||||
|
if (isDarkMode && mainContainer != null) {
|
||||||
|
mainContainer.getStyleClass().remove("root-light");
|
||||||
|
mainContainer.getStyleClass().add("root-dark");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Logic to add a specific song to the user's playlist.
|
@FXML
|
||||||
|
public void handleThemeToggle() {
|
||||||
|
isDarkMode = !isDarkMode;
|
||||||
|
if (isDarkMode) {
|
||||||
|
mainContainer.getStyleClass().remove("root-light");
|
||||||
|
mainContainer.getStyleClass().add("root-dark");
|
||||||
|
} else {
|
||||||
|
mainContainer.getStyleClass().remove("root-dark");
|
||||||
|
mainContainer.getStyleClass().add("root-light");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void handlePlaySong1() {
|
||||||
|
nowPlayingLabel.setText("Now Playing: Song of Dawn");
|
||||||
|
updateVisualFeedback(row1, playBtn1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void handlePlaySong2() {
|
||||||
|
nowPlayingLabel.setText("Now Playing: Midnight Drive");
|
||||||
|
updateVisualFeedback(row2, playBtn2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void handlePlaySong3() {
|
||||||
|
nowPlayingLabel.setText("Now Playing: Echoes of You");
|
||||||
|
updateVisualFeedback(row3, playBtn3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateVisualFeedback(HBox activeRow, Button activeBtn) {
|
||||||
|
// Clear previous selections
|
||||||
|
row1.getStyleClass().remove("playing-row");
|
||||||
|
row2.getStyleClass().remove("playing-row");
|
||||||
|
row3.getStyleClass().remove("playing-row");
|
||||||
|
|
||||||
|
playBtn1.setText("Play");
|
||||||
|
playBtn2.setText("Play");
|
||||||
|
playBtn3.setText("Play");
|
||||||
|
|
||||||
|
// Set active feedback
|
||||||
|
activeRow.getStyleClass().add("playing-row");
|
||||||
|
activeBtn.setText("Playing");
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void handleAddToPlaylistSong1() { addToPlaylist("Song of Dawn — Alice Johnson (03:45)"); }
|
||||||
|
@FXML public void handleAddToPlaylistSong2() { addToPlaylist("Midnight Drive — The Night Owls (04:12)"); }
|
||||||
|
@FXML public void handleAddToPlaylistSong3() { addToPlaylist("Echoes of You — Luna Sky (05:08)"); }
|
||||||
|
|
||||||
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.
|
public List<String> getPlaylist() { return playlist; }
|
||||||
|
|
||||||
|
@FXML
|
||||||
public void openPlaylistWindow() {
|
public void openPlaylistWindow() {
|
||||||
//Create a new stage and show the playlist UI.
|
try {
|
||||||
|
Stage stage = (Stage) nowPlayingLabel.getScene().getWindow();
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("Playlist-view.fxml"));
|
||||||
|
Scene scene = new Scene(fxmlLoader.load());
|
||||||
|
stage.setScene(scene);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package sbu.javafx;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class PlaylistController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<String> playlistListView;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
|
||||||
|
MusicController mainController = new MusicController();
|
||||||
|
playlistListView.getItems().addAll(mainController.getPlaylist());
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void backToMain() {
|
||||||
|
try {
|
||||||
|
Stage stage = (Stage) playlistListView.getScene().getWindow();
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
|
||||||
|
Scene scene = new Scene(fxmlLoader.load());
|
||||||
|
stage.setScene(scene);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,87 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
|
<?import javafx.scene.layout.GridPane?>
|
||||||
|
<?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.text.Font?>
|
||||||
|
|
||||||
<!-- TODO: Add your code here! -->
|
<VBox xmlns="http://javafx.com/javafx/17"
|
||||||
|
xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="sbu.javafx.MusicController"
|
||||||
|
fx:id="mainContainer"
|
||||||
|
alignment="TOP_CENTER"
|
||||||
|
spacing="20"
|
||||||
|
prefWidth="680.0"
|
||||||
|
prefHeight="520.0"
|
||||||
|
styleClass="root-light"
|
||||||
|
stylesheets="@style.css">
|
||||||
|
|
||||||
</VBox>
|
<padding>
|
||||||
|
<Insets top="20.0" right="20.0" bottom="20.0" left="20.0" />
|
||||||
|
</padding>
|
||||||
|
|
||||||
|
<HBox alignment="CENTER" spacing="150">
|
||||||
|
<Label text="Music Player">
|
||||||
|
<font>
|
||||||
|
<Font name="System Regular" size="28.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Button text="Toggle Theme" onAction="#handleThemeToggle" />
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
<GridPane hgap="10" vgap="0" style="-fx-border-color: black; -fx-border-width: 1;">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints percentWidth="25.0" />
|
||||||
|
<ColumnConstraints percentWidth="25.0" />
|
||||||
|
<ColumnConstraints percentWidth="12.0" />
|
||||||
|
<ColumnConstraints percentWidth="23.0" halignment="CENTER" />
|
||||||
|
<ColumnConstraints percentWidth="15.0" halignment="CENTER" />
|
||||||
|
</columnConstraints>
|
||||||
|
|
||||||
|
<HBox style="-fx-padding: 10;" GridPane.columnIndex="0" GridPane.columnSpan="5" GridPane.rowIndex="0">
|
||||||
|
<Label text="Song Title" style="-fx-font-weight: bold;" prefWidth="160"/>
|
||||||
|
<Label text="Artist Name" style="-fx-font-weight: bold;" prefWidth="160"/>
|
||||||
|
<Label text="Duration" style="-fx-font-weight: bold;" prefWidth="80"/>
|
||||||
|
<Label text="Add to Playlist" style="-fx-font-weight: bold;" prefWidth="150" alignment="CENTER"/>
|
||||||
|
<Label text="Play" style="-fx-font-weight: bold;" prefWidth="90" alignment="CENTER"/>
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
<HBox fx:id="row1" alignment="CENTER_LEFT" style="-fx-padding: 10; -fx-border-color: #cccccc; -fx-border-width: 1 0 0 0;" GridPane.columnIndex="0" GridPane.columnSpan="5" GridPane.rowIndex="1">
|
||||||
|
<Label text="Song of Dawn" prefWidth="160" />
|
||||||
|
<Label text="Alice Johnson" prefWidth="160" />
|
||||||
|
<Label text="03:45" prefWidth="80" />
|
||||||
|
<HBox prefWidth="150" alignment="CENTER"><Button text="Add to Playlist" onAction="#handleAddToPlaylistSong1" /></HBox>
|
||||||
|
<HBox prefWidth="90" alignment="CENTER"><Button fx:id="playBtn1" text="Play" onAction="#handlePlaySong1" prefWidth="75.0" /></HBox>
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
<HBox fx:id="row2" alignment="CENTER_LEFT" style="-fx-padding: 10; -fx-border-color: #cccccc; -fx-border-width: 1 0 0 0;" GridPane.columnIndex="0" GridPane.columnSpan="5" GridPane.rowIndex="2">
|
||||||
|
<Label text="Midnight Drive" prefWidth="160" />
|
||||||
|
<Label text="The Night Owls" prefWidth="160" />
|
||||||
|
<Label text="04:12" prefWidth="80" />
|
||||||
|
<HBox prefWidth="150" alignment="CENTER"><Button text="Add to Playlist" onAction="#handleAddToPlaylistSong2" /></HBox>
|
||||||
|
<HBox prefWidth="90" alignment="CENTER"><Button fx:id="playBtn2" text="Play" onAction="#handlePlaySong2" prefWidth="75.0" /></HBox>
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
<HBox fx:id="row3" alignment="CENTER_LEFT" style="-fx-padding: 10; -fx-border-color: #cccccc; -fx-border-width: 1 0 1 0;" GridPane.columnIndex="0" GridPane.columnSpan="5" GridPane.rowIndex="3">
|
||||||
|
<Label text="Echoes of You" prefWidth="160" />
|
||||||
|
<Label text="Luna Sky" prefWidth="160" />
|
||||||
|
<Label text="05:08" prefWidth="80" />
|
||||||
|
<HBox prefWidth="150" alignment="CENTER"><Button text="Add to Playlist" onAction="#handleAddToPlaylistSong3" /></HBox>
|
||||||
|
<HBox prefWidth="90" alignment="CENTER"><Button fx:id="playBtn3" text="Play" onAction="#handlePlaySong3" prefWidth="75.0" /></HBox>
|
||||||
|
</HBox>
|
||||||
|
</GridPane>
|
||||||
|
|
||||||
|
<HBox alignment="CENTER_LEFT" style="-fx-border-color: black; -fx-border-width: 1; -fx-padding: 20;">
|
||||||
|
<Label fx:id="nowPlayingLabel" text="Now Playing: -" HBox.hgrow="ALWAYS" maxWidth="Infinity">
|
||||||
|
<font>
|
||||||
|
<Font size="14.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Button text="Open Playlist" onAction="#openPlaylistWindow" prefWidth="120.0" prefHeight="35.0" />
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
</VBox>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.ListView?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
|
<VBox alignment="TOP_CENTER" prefHeight="400.0" prefWidth="500.0" spacing="15.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sbu.javafx.PlaylistController">
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
||||||
|
</padding>
|
||||||
|
|
||||||
|
<Label text="Your Custom Playlist">
|
||||||
|
<font>
|
||||||
|
<Font name="System Bold" size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<ListView fx:id="playlistListView" VBox.vgrow="ALWAYS" />
|
||||||
|
|
||||||
|
<Button onAction="#backToMain" text="Back to Player" style="-fx-background-color: #2196F3; -fx-text-fill: white;" />
|
||||||
|
</VBox>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/* Light Mode (Default) */
|
||||||
|
.root-light {
|
||||||
|
-fx-background-color: white;
|
||||||
|
-fx-text-fill: black;
|
||||||
|
}
|
||||||
|
.root-light .label {
|
||||||
|
-fx-text-fill: black;
|
||||||
|
}
|
||||||
|
.root-light .button {
|
||||||
|
-fx-background-color: white;
|
||||||
|
-fx-border-color: black;
|
||||||
|
-fx-text-fill: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dark Mode */
|
||||||
|
.root-dark {
|
||||||
|
-fx-background-color: #1e1e1e;
|
||||||
|
}
|
||||||
|
.root-dark .label {
|
||||||
|
-fx-text-fill: white;
|
||||||
|
}
|
||||||
|
.root-dark .button {
|
||||||
|
-fx-background-color: #333333;
|
||||||
|
-fx-border-color: #555555;
|
||||||
|
-fx-text-fill: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Active Visual Feedback Style */
|
||||||
|
.playing-row {
|
||||||
|
-fx-background-color: #e0f7fa;
|
||||||
|
}
|
||||||
|
.root-dark .playing-row {
|
||||||
|
-fx-background-color: #004d40;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user