WIP: fininsh #1

Draft
mahdi_Goudarzi wants to merge 1 commits from develop into main
10 changed files with 422 additions and 11 deletions
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

+2 -1
View File
@@ -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);
}
}
+7 -1
View File
@@ -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();
}
+150 -7
View File
@@ -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<String> playList= new ArrayList<String>();
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");
}
}
}
@@ -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<String> 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));
}
}
+60 -2
View File
@@ -1,8 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Separator?>
<VBox xmlns:fx="http://javafx.com/fxml" alignment="CENTER" spacing="30" fx:controller="sbu.javafx.MusicController">
<padding><Insets top="30" right="30" left="30" bottom="20"/></padding>
<HBox alignment="CENTER" spacing="10" >
<Label fx:id="titleLabel" text = "Music Player" styleClass="title"/>
<Button fx:id="mode" text="Switch to dark mode" styleClass="mode" onAction="#chagemode" />
</HBox>
<HBox spacing="10" alignment="CENTER" styleClass="fisrtrow">
<Label text="Song title" prefWidth="100" styleClass="Songtitle"/>
<Label text="Artist name" prefWidth="100" styleClass="Artistname"/>
<Label text="Duration" prefWidth="100" styleClass="Dur"/>
<Label text="Add to play list" prefWidth="150" styleClass="ADDtp"/>
<Label text="PLay" prefWidth="70" styleClass="play"/>
</HBox>
<Separator/>
<HBox spacing="10" alignment="CENTER">
<Label text="Ey iran" prefWidth="100"/>
<Label text="Banan" prefWidth="100"/>
<Label text="2:59" prefWidth="100"/>
<Button fx:id="addPl1" text="ADD Music 1" prefWidth="100" styleClass="but" onAction="#addToPlaylist" />
<Button fx:id="play1" text="Play" prefWidth="100" onAction="#playsong1" styleClass="but"/>
</HBox>
<Separator/>
<HBox spacing="10" alignment="CENTER">
<Label text="Mahe Man" prefWidth="100"/>
<Label text="Ehsan Yasin" prefWidth="100"/>
<Label text="3:36" prefWidth="100"/>
<Button fx:id="addPl2" text="ADD Music 2" prefWidth="100" styleClass="but" onAction="#addToPlaylist" />
<Button fx:id="play2" text="Play" prefWidth="100" onAction="#playsong2" styleClass="but"/>
</HBox>
<Separator/>
<HBox spacing="10" alignment="CENTER">
<Label text="Interstellar" prefWidth="100" />
<Label text="Kwoon" prefWidth="100"/>
<Label text="4:13" prefWidth="100"/>
<Button fx:id="addPl3" text="ADD Music 3" prefWidth="100" styleClass="but" onAction="#addToPlaylist"/>
<Button fx:id="play3" text="Play" prefWidth="100" onAction="#playsong3" styleClass="but"/>
</HBox>
<HBox>
<Label fx:id="nowPlaying" text="Now playing:" prefWidth="200"/>
<Label text="" prefWidth="200"/>
<Button text="Open playlist" prefWidth="200" styleClass="but" onAction="#openPlaylistWindow"/>
</HBox>
<!-- TODO: Add your code here! -->
</VBox>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Separator?>
<VBox xmlns:fx="http://javafx.com/fxml" alignment="CENTER" spacing="30" fx:controller="sbu.javafx.PlaylistController">
<padding><Insets top="30" right="30" left="30" bottom="20"/></padding>
<VBox spacing="5">
<Label text="My play list" styleClass="title"/>
<Separator/>
<Label fx:id="PL1" />
<Label fx:id="PL2" />
<Label fx:id="PL3" />
</VBox>
</VBox>
+66
View File
@@ -0,0 +1,66 @@
.root{
-fx-background-color: #121212;
-fx-font-family: "DejaVu Sans", "Segoe UI", sans-serif;
}
.title {
-fx-font-size: 28px;
-fx-font-weight: bold;
-fx-text-fill: #FFFFFF;
}
.fisrtrow {
-fx-border-color: #444444;
-fx-border-width: 1 1 1 1;
-fx-padding: 10;
-fx-background-color: #1E1E1E;
}
.mode{
-fx-background-color: #333333; /* رنگ جدید دکمه */
-fx-text-fill: #FFFFFF;
-fx-font-size: 12px;
-fx-font-weight: bold;
-fx-padding: 8 16;
-fx-background-radius: 6;
-fx-cursor: hand;
}
.Songtitle{
-fx-font-weight: bold;
-fx-text-fill: #FFFFFF;
}
.Artistname{
-fx-font-weight: bold;
-fx-text-fill: #FFFFFF;
}
.Dur{
-fx-font-weight: bold;
-fx-text-fill: #FFFFFF;
}
.ADDtp{
-fx-font-weight: bold;
-fx-text-fill: #FFFFFF;
}
.play{
-fx-font-weight: bold;
-fx-text-fill: #FFFFFF;
}
.but {
-fx-background-color: linear-gradient(to bottom, #4A4A4A, #2C2C2C);
-fx-text-fill: #FFFFFF;
-fx-font-weight: bold;
-fx-background-radius: 10;
-fx-border-radius: 10;
-fx-padding: 2 4;
-fx-cursor: hand;
}
.but:pressed {
-fx-background-color: #1A1A1A;
}
+69
View File
@@ -0,0 +1,69 @@
.root{
-fx-background-color: #F0FFFF;
-fx-font-family: "DejaVu Sans", "Segoe UI", sans-serif;
}
.title {
-fx-font-size: 28px;
-fx-font-weight: bold;
-fx-text-fill: #0000FF ;
}
.fisrtrow {
-fx-border-color: #4a90e2;
-fx-border-width: 1 1 1 1;
-fx-padding: 10;
-fx-background-color: #f0f0f0;
}
.mode{
-fx-background-color: #4CAF50;
-fx-text-fill: white;
-fx-font-size: 12px;
-fx-font-weight: bold;
-fx-padding: 8 16;
-fx-background-radius: 6;
-fx-cursor: hand;
}
.Songtitle{
-fx-font-weight: bold;
-fx-text-fill: #0000FF ;
}
.Artistname{
-fx-font-weight: bold;
-fx-text-fill: #0000FF ;
}
.Dur{
-fx-font-weight: bold;
-fx-text-fill: #0000FF ;
}
.ADDtp{
-fx-font-weight: bold;
-fx-text-fill: #0000FF ;
}
.play{
-fx-font-weight: bold;
-fx-text-fill: #0000FF ;
}
.but {
-fx-background-color: linear-gradient(to bottom, #4caf50, #2e7d32);
-fx-text-fill: white;
-fx-font-weight: bold;
-fx-background-radius: 10;
-fx-border-radius: 10;
-fx-padding: 2 4;
-fx-cursor: hand;
}
.but:pressed {
-fx-background-color: #1b5e20;
}