diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/sbu/javafx/Launcher.java b/src/main/java/sbu/javafx/Launcher.java index c288d10..e3e4a1d 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -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); + } +} \ No newline at end of file diff --git a/src/main/java/sbu/javafx/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java index a50badc..c86a173 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -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(); } - -} +} \ No newline at end of file diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..c6f70df 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -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 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 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); } -} +} \ No newline at end of file diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 306c8d3..f5c6329 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,43 @@ - - + + + - + - +