diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..8306744 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ 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..a3ffd1f 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -4,5 +4,6 @@ import javafx.application.Application; public class Launcher{ public static void main(String[] args) { - // TODO: Launch the JavaFX application by calling Application.launch(Main.class) } + Application.launch(MusicApp.class); + } } diff --git a/src/main/java/sbu/javafx/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java index a50badc..863e864 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -4,7 +4,9 @@ import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; +import javafx.scene.image.Image; +import java.awt.*; import java.io.IOException; public class MusicApp extends Application { @@ -16,7 +18,13 @@ public class MusicApp extends Application { Scene scene = new Scene(fxmlLoader.load()); stage.setTitle("Music Player"); stage.setScene(scene); - //TODO: add icon to the stage + scene.getStylesheets().add(getClass().getResource("light.css").toExternalForm()); + stage.setWidth(1100); + stage.setHeight(500); + + Image icon = new Image(getClass().getResourceAsStream("icon.png")); + stage.getIcons().add(icon); + stage.show(); } diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..c417ce9 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -1,31 +1,148 @@ package sbu.javafx; -import javafx.fxml.FXML; import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.Scene; +import javafx.scene.control.Button; import javafx.scene.control.Label; -import javafx.scene.input.MouseEvent; +import javafx.scene.layout.HBox; 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. + public Label Name1; + public Label Singer1; + public Button AddToPlaylist1; + public Button play1; + + public Label Name2; + public Label Singer2; + public Button AddToPlaylist2; + public Button play2; + + public Label Name3; + public Label Singer3; + public Button AddToPlaylist3; + public Button play3; + + public HBox song1; + public HBox song2; + public HBox song3; + public HBox header; + public HBox playingBox; + + boolean isDark = false; + Button currentPlayingSong = null; + public Label nowPlayingSong; + public Button themeToggle; + public Button PlayListButton; + + ArrayList playlist = new ArrayList<>(); + boolean onPlaylist1 = false; + boolean onPlaylist2 = false; + boolean onPlaylist3 = false; - //TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. + public void handlePlayAction(ActionEvent actionEvent) { + Button button = (Button) actionEvent.getSource(); + + if(currentPlayingSong == button) { + currentPlayingSong.setText("Play"); + nowPlayingSong.setText(" "); + currentPlayingSong = null; + return; + } + + if(currentPlayingSong != null) { + currentPlayingSong.setText("Play"); + } + + + currentPlayingSong = button; + currentPlayingSong.setText("Playing..."); + + if(currentPlayingSong == play1) { + nowPlayingSong.setText(Name1.getText() + " | " + Singer1.getText()); + } + else if(currentPlayingSong == play2) { + nowPlayingSong.setText(Name2.getText() + " | " + Singer2.getText()); + } + else if (currentPlayingSong == play3) { + nowPlayingSong.setText(Name3.getText() + " | " + Singer3.getText()); + } } - //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. + @FXML + public void addToPlaylist(ActionEvent event) { + + Button button = (Button) event.getSource(); + + if(button == AddToPlaylist1 && !onPlaylist1) { + playlist.add(song1); + AddToPlaylist1.setText("On Playlist"); + onPlaylist1 = true; + } + else if(button == AddToPlaylist2 && !onPlaylist2) { + playlist.add(song2); + AddToPlaylist2.setText("On Playlist"); + onPlaylist2 = true; + } + else if(button == AddToPlaylist3 && !onPlaylist3) { + playlist.add(song3); + AddToPlaylist3.setText("On Playlist"); + onPlaylist3 = true; + } } - // TODO:This method should open a new window or change the current scene to display the "Playlist" page. + public void openPlaylistWindow(ActionEvent event) { - public void openPlaylistWindow() { - //Create a new stage and show the playlist UI. + Button button = (Button) event.getSource(); + + Stage stage = (Stage) button.getScene().getWindow(); + + stage.setTitle("Playlist"); + VBox root = new VBox(); + + if(!playlist.isEmpty()){ + root.getChildren().add(header); + root.getChildren().addAll(playlist); + root.getChildren().add(playingBox); + } + else { + Label label = new Label("Your playlist is empty."); + if(!isDark) + label.setStyle("-fx-font-size: 24px;"); + else + label.setStyle("-fx-font-size: 24px; ; -fx-text-fill: #e0e0e0;"); + root.getChildren().add(label); + } + + + Scene scene = new Scene(root); + if(!isDark) + scene.getStylesheets().add(getClass().getResource("light.css").toExternalForm()); + else + scene.getStylesheets().add(getClass().getResource("dark.css").toExternalForm()); + + stage.setScene(scene); + } + + @FXML + public void toggleTheme() { + isDark = !isDark; + themeToggle.getScene().getStylesheets().clear(); + if(isDark) { + themeToggle.getScene().getStylesheets().add(getClass().getResource("dark.css").toExternalForm()); + themeToggle.setText("Switch to Light Mode"); + } + else { + themeToggle.getScene().getStylesheets().add(getClass().getResource("light.css").toExternalForm()); + themeToggle.setText("Switch to Dark Mode"); + } } } diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 306c8d3..ec20d3d 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,50 @@ - + + + - + + + +