forked from AdvancedProgramming1404/HW-07-JavaFX
tamrin 7
This commit is contained in:
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>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package sbu.javafx;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -13,10 +15,14 @@ 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(),600,350);
|
||||
stage.setTitle("Music Player");
|
||||
stage.setScene(scene);
|
||||
//TODO: add icon to the stage
|
||||
Image icon = new Image(getClass().getResource("dextericon.png").toExternalForm());
|
||||
stage.getIcons().add(icon);
|
||||
stage.setTitle("Dexter Music Player");
|
||||
stage.setScene(scene);
|
||||
|
||||
stage.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,30 +2,112 @@ package sbu.javafx;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
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 lblNowPlaying;
|
||||
|
||||
@FXML
|
||||
public void handlePlayAction() {
|
||||
//Update labels, change button icons, etc.
|
||||
private Button btnPlay1, btnPlay2, btnPlay3;
|
||||
|
||||
@FXML
|
||||
private Button btnAdd1, btnAdd2, btnAdd3;
|
||||
|
||||
@FXML
|
||||
private Button btnOpenPlaylist;
|
||||
private ArrayList<String> playlist = new ArrayList<>();
|
||||
private Scene mainScene;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
mainScene = lblNowPlaying.getScene();
|
||||
}
|
||||
|
||||
|
||||
@FXML
|
||||
public void handlePlayAction(ActionEvent event) {
|
||||
Button clickedButton = (Button) event.getSource();
|
||||
String songName = "";
|
||||
|
||||
if (clickedButton == btnPlay1) {
|
||||
songName = "Song of Dawn - Alice Johnson";
|
||||
} else if (clickedButton == btnPlay2) {
|
||||
songName = "Midnight Drive - The Night Owls";
|
||||
} else if (clickedButton == btnPlay3) {
|
||||
songName = "Echoes of You - Luna Sky";
|
||||
}
|
||||
|
||||
if (lblNowPlaying != null) {
|
||||
lblNowPlaying.setText("Now Playing: " + songName);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleAddToPlaylistAction(ActionEvent event) {
|
||||
Button clickedButton = (Button) event.getSource();
|
||||
String songName = "";
|
||||
|
||||
if (clickedButton == btnAdd1) {
|
||||
songName = "Song of Dawn - Alice Johnson";
|
||||
} else if (clickedButton == btnAdd2) {
|
||||
songName = "Midnight Drive - The Night Owls";
|
||||
} else if (clickedButton == btnAdd3) {
|
||||
songName = "Echoes of You - Luna Sky";
|
||||
}
|
||||
|
||||
addToPlaylist(songName);
|
||||
}
|
||||
|
||||
//TODO: Logic to add a specific song to the user's playlist.
|
||||
|
||||
public void addToPlaylist(String songName) {
|
||||
//Add the song to a list or update a ListView.
|
||||
if (songName != null && !songName.isEmpty()) {
|
||||
playlist.add(songName);
|
||||
System.out.println("Added: " + songName);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:This method should open a new window or change the current scene to display the "Playlist" page.
|
||||
|
||||
public void openPlaylistWindow() {
|
||||
//Create a new stage and show the playlist UI.
|
||||
public void openPlaylistWindow(ActionEvent event) {
|
||||
Stage currentStage = (Stage) ((Button) event.getSource()).getScene().getWindow();
|
||||
mainScene = currentStage.getScene();
|
||||
|
||||
VBox playlistLayout = new VBox(10);
|
||||
playlistLayout.setStyle("-fx-padding: 20; -fx-alignment: top-center;");
|
||||
|
||||
Label titleLabel = new Label("Your Playlist:");
|
||||
titleLabel.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;");
|
||||
playlistLayout.getChildren().add(titleLabel);
|
||||
|
||||
if (playlist.isEmpty()) {
|
||||
playlistLayout.getChildren().add(new Label("Your playlist is empty."));
|
||||
} else {
|
||||
for (String song : playlist) {
|
||||
playlistLayout.getChildren().add(new Label("- " + song));
|
||||
}
|
||||
}
|
||||
|
||||
Button backButton = new Button("Back to Music Player");
|
||||
backButton.setOnAction(e -> {
|
||||
Stage stage = (Stage) backButton.getScene().getWindow();
|
||||
stage.setScene(mainScene);
|
||||
stage.setTitle("Music Player");
|
||||
});
|
||||
playlistLayout.getChildren().add(backButton);
|
||||
|
||||
Scene playlistScene = new Scene(playlistLayout, 400, 500);
|
||||
currentStage.setScene(playlistScene);
|
||||
currentStage.setTitle("Playlist");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,47 @@
|
||||
<?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.HBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
|
||||
<!-- TODO: Add your code here! -->
|
||||
<VBox xmlns="http://javafx.com/javafx/21"
|
||||
xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="sbu.javafx.MusicController"
|
||||
alignment="CENTER" spacing="10"
|
||||
style="-fx-padding: 20; -fx-background-color: #87CEEB;">
|
||||
|
||||
|
||||
|
||||
<HBox spacing="20.0" alignment="CENTER"
|
||||
style="-fx-background-color: white; -fx-padding: 10; -fx-border-color: #FF0000; -fx-border-radius: 5;">
|
||||
<Label text="Dexter Main Title" prefWidth="120.0"/>
|
||||
<Label text="Rolfe Ken" prefWidth="120.0"/>
|
||||
<Label text="01:41" prefWidth="60.0"/>
|
||||
<Button fx:id="btnAdd1" onAction="#handleAddToPlaylistAction" text="Add to Playlist"/>
|
||||
<Button fx:id="btnPlay1" onAction="#handlePlayAction" text="Play"/>
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="20.0" alignment="CENTER"
|
||||
style="-fx-background-color: white; -fx-padding: 10; -fx-border-color: #FF0000; -fx-border-radius: 5;">
|
||||
<Label text="Blood Theme" prefWidth="120.0"/>
|
||||
<Label text="Daniel Licht" prefWidth="120.0"/>
|
||||
<Label text="02:26" prefWidth="60.0"/>
|
||||
<Button fx:id="btnAdd2" onAction="#handleAddToPlaylistAction" text="Add to Playlist"/>
|
||||
<Button fx:id="btnPlay2" onAction="#handlePlayAction" text="Play"/>
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="20.0" alignment="CENTER"
|
||||
style="-fx-background-color: white; -fx-padding: 10; -fx-border-color: #FF0000; -fx-border-radius: 5;">
|
||||
<Label text="Born Free" prefWidth="120.0"/>
|
||||
<Label text="Andy Williams" prefWidth="120.0"/>
|
||||
<Label text="02:26" prefWidth="60.0"/>
|
||||
<Button fx:id="btnAdd3" onAction="#handleAddToPlaylistAction" text="Add to Playlist"/>
|
||||
<Button fx:id="btnPlay3" onAction="#handlePlayAction" text="Play"/>
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="20.0" alignment="CENTER">
|
||||
<Label fx:id="lblNowPlaying" text="Now Playing: -" prefWidth="250.0" style="-fx-font-style: italic;"/>
|
||||
<Button fx:id="btnOpenPlaylist" onAction="#openPlaylistWindow" text="Open Playlist"/>
|
||||
</HBox>
|
||||
</VBox>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
Reference in New Issue
Block a user