Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb6a206a82 | ||
|
|
5e6c37e89b | ||
|
|
69e0b92bcd |
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,8 @@ package sbu.javafx;
|
||||
|
||||
import javafx.application.Application;
|
||||
|
||||
public class Launcher{
|
||||
public class Launcher {
|
||||
public static void main(String[] args) {
|
||||
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) }
|
||||
}
|
||||
Application.launch(MusicApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package sbu.javafx;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -13,11 +14,16 @@ public class MusicApp extends Application {
|
||||
public void start(Stage stage) throws IOException
|
||||
{
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
Scene scene = new Scene(fxmlLoader.load(), 450, 350);
|
||||
stage.setTitle("Music Player");
|
||||
|
||||
try {
|
||||
stage.getIcons().add(new Image(MusicApp.class.getResourceAsStream("icon.png")));
|
||||
} catch (Exception ignored) {
|
||||
// Icon file not found, continuing without icon
|
||||
}
|
||||
|
||||
stage.setScene(scene);
|
||||
//TODO: add icon to the stage
|
||||
stage.show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,30 +2,68 @@ package sbu.javafx;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.geometry.Pos;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MusicController {
|
||||
|
||||
// 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.
|
||||
@FXML
|
||||
private Label nowPlayingLabel;
|
||||
|
||||
@FXML
|
||||
public void handlePlayAction() {
|
||||
//Update labels, change button icons, etc.
|
||||
private VBox rootContainer;
|
||||
|
||||
private static ArrayList<String> playlist = new ArrayList<>();
|
||||
|
||||
@FXML
|
||||
public void handlePlayAction(ActionEvent event) {
|
||||
Button clickedButton = (Button) event.getSource();
|
||||
String songName = (String) clickedButton.getUserData();
|
||||
nowPlayingLabel.setText("Now Playing: " + songName);
|
||||
}
|
||||
|
||||
//TODO: Logic to add a specific song to the user's playlist.
|
||||
@FXML
|
||||
public void handleAddAction(ActionEvent event) {
|
||||
Button clickedButton = (Button) event.getSource();
|
||||
String songName = (String) clickedButton.getUserData();
|
||||
addToPlaylist(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 openPlaylistWindow() {
|
||||
//Create a new stage and show the playlist UI.
|
||||
Stage stage = (Stage) rootContainer.getScene().getWindow();
|
||||
|
||||
ListView<String> listView = new ListView<>();
|
||||
listView.getItems().addAll(playlist);
|
||||
|
||||
Button backButton = new Button("Back");
|
||||
backButton.setOnAction(e -> {
|
||||
try {
|
||||
javafx.fxml.FXMLLoader fxmlLoader = new javafx.fxml.FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), 800, 600);
|
||||
stage.setScene(scene);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
VBox vbox = new VBox(15, new Label("Your Playlist"), listView, backButton);
|
||||
vbox.setAlignment(Pos.CENTER);
|
||||
vbox.setStyle("-fx-padding: 30px;");
|
||||
|
||||
Scene playlistScene = new Scene(vbox, 800, 600);
|
||||
stage.setScene(playlistScene);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
|
||||
<!-- TODO: Add your code here! -->
|
||||
<VBox fx:id="rootContainer" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" fx:controller="sbu.javafx.MusicController" alignment="TOP_CENTER" spacing="30" style="-fx-padding: 30px;">
|
||||
|
||||
</VBox>
|
||||
<Label text="Music Player" style="-fx-font-size: 28px; -fx-font-weight: normal;"/>
|
||||
|
||||
<GridPane alignment="CENTER" hgap="30" vgap="20" style="-fx-border-color: black; -fx-border-width: 1px; -fx-padding: 20px;">
|
||||
|
||||
<Label text="Song Title" style="-fx-font-weight: bold;" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
|
||||
<Label text="Artist Name" 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"/>
|
||||
<Label text="Add to Playlist" style="-fx-font-weight: bold;" GridPane.columnIndex="3" GridPane.rowIndex="0" GridPane.halignment="CENTER"/>
|
||||
<Label text="Play" style="-fx-font-weight: bold;" GridPane.columnIndex="4" GridPane.rowIndex="0" GridPane.halignment="CENTER"/>
|
||||
|
||||
<Label text="Song of Dawn" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
|
||||
<Label text="Alice Johnson" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
|
||||
<Label text="03:45" GridPane.columnIndex="2" GridPane.rowIndex="1"/>
|
||||
<Button text="Add to Playlist" onAction="#handleAddAction" userData="Song of Dawn" GridPane.columnIndex="3" GridPane.rowIndex="1"/>
|
||||
<Button text="Play" onAction="#handlePlayAction" userData="Song of Dawn" GridPane.columnIndex="4" GridPane.rowIndex="1"/>
|
||||
|
||||
<Label text="Midnight Drive" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
|
||||
<Label text="The Night Owls" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
|
||||
<Label text="04:12" GridPane.columnIndex="2" GridPane.rowIndex="2"/>
|
||||
<Button text="Add to Playlist" onAction="#handleAddAction" userData="Midnight Drive" GridPane.columnIndex="3" GridPane.rowIndex="2"/>
|
||||
<Button text="Play" onAction="#handlePlayAction" userData="Midnight Drive" GridPane.columnIndex="4" GridPane.rowIndex="2"/>
|
||||
|
||||
<Label text="Echoes of You" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
|
||||
<Label text="Luna Sky" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
|
||||
<Label text="05:08" GridPane.columnIndex="2" GridPane.rowIndex="3"/>
|
||||
<Button text="Add to Playlist" onAction="#handleAddAction" userData="Echoes of You" GridPane.columnIndex="3" GridPane.rowIndex="3"/>
|
||||
<Button text="Play" onAction="#handlePlayAction" userData="Echoes of You" GridPane.columnIndex="4" GridPane.rowIndex="3"/>
|
||||
</GridPane>
|
||||
|
||||
<HBox alignment="CENTER_LEFT" spacing="20" style="-fx-border-color: black; -fx-border-width: 1px; -fx-padding: 20px;">
|
||||
<Label fx:id="nowPlayingLabel" text="Now Playing: -" style="-fx-font-size: 16px;" HBox.hgrow="ALWAYS" maxWidth="Infinity"/>
|
||||
<Region HBox.hgrow="ALWAYS"/> <Button text="Open Playlist" onAction="#openPlaylistWindow" style="-fx-padding: 8px 15px;"/>
|
||||
</HBox>
|
||||
|
||||
</VBox>
|
||||
Reference in New Issue
Block a user