diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..46ff180 Binary files /dev/null and b/icon.png differ 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..cc7be6d 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -3,9 +3,11 @@ 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; +import java.util.Objects; public class MusicApp extends Application { @@ -14,9 +16,13 @@ public class MusicApp extends Application { { FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml")); Scene scene = new Scene(fxmlLoader.load()); + + scene.getStylesheets().add(getClass().getResource("light.css").toExternalForm()); + stage.setTitle("Music Player"); stage.setScene(scene); - //TODO: add icon to the stage + + //stage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/icon.png")))); stage.show(); } diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..c90ff4d 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -2,30 +2,173 @@ package sbu.javafx; import javafx.fxml.FXML; import javafx.event.ActionEvent; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +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.io.IOException; +import java.util.ArrayList; +import java.util.Objects; public class MusicController { + @FXML private Button mode; + @FXML private Button play1; + @FXML private Button play2; + @FXML private Button play3; + @FXML private Button addPl1; + @FXML private Button addPl2; + @FXML private Button addPl3; + @FXML private Label nowPlaying; - // 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. + + + private ArrayList playList= new ArrayList(); + private Scene scene; + private boolean darkmode=false; + @FXML - public void handlePlayAction() { - //Update labels, change button icons, etc. + public void playsong1(){ + if(play1.getText().equals("Play")){ + play1.setText("Pasue"); + play2.setText("Play"); + play3.setText("Play"); + nowPlaying.setText("Now playing: Ey iran - Banan"); + }else { + play1.setText("Play"); + nowPlaying.setText("Now playing :"); + } + + } + + @FXML + public void playsong2(){ + if(play2.getText().equals("Play")){ + play2.setText("Pasue"); + play1.setText("Play"); + play3.setText("Play"); + nowPlaying.setText("Now playing: Mahe man - Ehsan Yasin"); + }else { + play2.setText("Play"); + nowPlaying.setText("Now playing :"); + } + + } + + @FXML + public void playsong3(){ + if(play3.getText().equals("Play")){ + play3.setText("Pasue"); + play1.setText("Play"); + play2.setText("Play"); + nowPlaying.setText("Now playing: Interstellar - Knoow"); + }else { + play3.setText("Play"); + nowPlaying.setText("Now playing :"); + } + } //TODO: Logic to add a specific song to the user's playlist. - public void addToPlaylist(String songName) { + public void addToPlaylist(ActionEvent event) { + Button clicked = (Button) event.getSource(); + String songcode = clicked.getText(); + + switch (songcode){ + case "ADD Music 1" :{ + playList.add("Ey iran -Banan"); + clicked.setText("Remove Music 1"); + break; + } + case "ADD Music 2":{ + playList.add("Mahe man - Ehsan Yassin"); + clicked.setText("Remove Music 2"); + break; + } + case "ADD Music 3":{ + playList.add("Interstellar - Knoow"); + clicked.setText("Remove Music 3"); + break; + } + case "Remove Music 1":{ + playList.remove("Ey iran -Banan"); + clicked.setText("ADD Music 1"); + break; + } + case "Remove Music 2":{ + playList.remove("Mahe man - Ehsan Yassin"); + clicked.setText("ADD Music 2"); + break; + } + case "Remove Music 3":{ + playList.remove("Interstellar - Knoow"); + clicked.setText("ADD Music 3"); + break; + } + + + + } + + + //Add the song to a list or update a ListView. } - // TODO:This method should open a new window or change the current scene to display the "Playlist" page. + private void showAlert(String message ) { + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setHeaderText(message); + alert.show(); + } - public void openPlaylistWindow() { + + public void openPlaylistWindow() throws IOException,NullPointerException { + + FXMLLoader fxmlLoader = new FXMLLoader(MusicController.class.getResource("Playlist-view.fxml")); + + scene = new Scene(fxmlLoader.load()); + if(darkmode){ + scene.getStylesheets().add(getClass().getResource("dark.css").toExternalForm()); + }else { + scene.getStylesheets().add(getClass().getResource("light.css").toExternalForm()); + } + PlaylistController plc = fxmlLoader.getController(); + plc.setPlaylist(playList); + Stage playlistStage = new Stage(); + playlistStage.setScene(scene); + + playlistStage.setTitle("Play list"); + playlistStage.show(); //Create a new stage and show the playlist UI. } + + + + + public void chagemode(){ + darkmode = !darkmode; + mode.getScene().getStylesheets().clear(); + if(darkmode){ + mode.getScene().getStylesheets().add(getClass().getResource("dark.css").toExternalForm()); + mode.setText("Swithch to light mode"); + } + else { + mode.getScene().getStylesheets().add(getClass().getResource("light.css").toExternalForm()); + mode.setText("Swithch to dark mode"); + + } + + + + + } + + } diff --git a/src/main/java/sbu/javafx/PlaylistController.java b/src/main/java/sbu/javafx/PlaylistController.java new file mode 100644 index 0000000..86e2c62 --- /dev/null +++ b/src/main/java/sbu/javafx/PlaylistController.java @@ -0,0 +1,39 @@ +package sbu.javafx; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; + +import java.util.ArrayList; + +public class PlaylistController { + + @FXML private Label PL1; + @FXML private Label PL2; + @FXML private Label PL3; + + + public void setPlaylist(ArrayList songs){ + + + PL1.setText(""); + PL2.setText(""); + PL3.setText(""); + + if (songs.size() > 0) PL1.setText(songs.get(0)); + if (songs.size() > 1) PL2.setText(songs.get(1)); + if (songs.size() > 2) PL3.setText(songs.get(2)); + + + + + } + + + + + + + + + +} diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 306c8d3..09a8a94 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,66 @@ - + + + + + + + + + + + +