From 98f8235fc35e1a3f6df4831939e16990ee5d9dc3 Mon Sep 17 00:00:00 2001 From: Bita Date: Fri, 29 May 2026 12:15:06 +0330 Subject: [PATCH] Add Style --- src/main/java/sbu/javafx/MusicApp.java | 11 +++- src/main/java/sbu/javafx/MusicController.java | 20 ++++++- src/main/resources/sbu/javafx/App-view.fxml | 8 ++- src/main/resources/sbu/javafx/icon.png | Bin 0 -> 16877 bytes src/main/resources/sbu/javafx/light.css | 49 ++++++++++++++++++ src/main/resources/sbu/javafx/style.css | 49 ++++++++++++++++++ 6 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/sbu/javafx/icon.png create mode 100644 src/main/resources/sbu/javafx/light.css create mode 100644 src/main/resources/sbu/javafx/style.css diff --git a/src/main/java/sbu/javafx/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java index 0ac846c..20c731a 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -4,7 +4,8 @@ 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 { @@ -14,8 +15,16 @@ public class MusicApp extends Application { { FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml")); Scene scene = new Scene(fxmlLoader.load()); + + String lightStyle = getClass().getResource("light.css").toExternalForm(); + scene.getStylesheets().add(lightStyle); + stage.setTitle("Music Player"); stage.setScene(scene); + + 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 2f036fe..ce8d4cc 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -19,6 +19,7 @@ public class MusicController { @FXML private ListView lvSongs; @FXML private Label lblStatus; @FXML private Button btnPlayStop; + @FXML private Button btnTheme; private int previousSongIndex = -1; @@ -26,7 +27,7 @@ public class MusicController { private ArrayList playlist = new ArrayList<>(); - private String[] songsArray = {"Arcade Duncan Laurence 3.07", + private String[] songsArray = {"Arcade Duncan Laurence 3.07", "How i love you Engelbert 4.20", "Memories Conan Gray 4.09", "Night Changes One Direction 3.47", @@ -158,4 +159,21 @@ public class MusicController { stage.setScene(scene); stage.show(); } + + @FXML + private void toggleTheme() + { + if (!btnTheme.getText().contains("Light")) + { + btnTheme.getScene().getStylesheets().clear(); + btnTheme.getScene().getStylesheets().add(getClass().getResource("style.css").toExternalForm()); + btnTheme.setText("Light Mode"); + } + else + { + btnTheme.getScene().getStylesheets().clear(); + btnTheme.getScene().getStylesheets().add(getClass().getResource("light.css").toExternalForm()); + btnTheme.setText("Dark Mode"); + } + } } \ 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 c1c0bf6..c3a0f6d 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -6,13 +6,19 @@ + + + + +