1 Commits
Author SHA1 Message Date
Parmis_jamami 88309de57e complete code 2026-05-30 21:06:12 +03:30
5 changed files with 117 additions and 18 deletions
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
+2 -1
View File
@@ -4,5 +4,6 @@ import javafx.application.Application;
public class Launcher{ public class Launcher{
public static void main(String[] args) { public static void main(String[] args) {
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) } Application.launch(MusicApp.class, args);
}
} }
+6 -2
View File
@@ -13,10 +13,14 @@ public class MusicApp extends Application {
public void start(Stage stage) throws IOException public void start(Stage stage) throws IOException
{ {
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml")); FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
Scene scene = new Scene(fxmlLoader.load()); Scene scene = new Scene(fxmlLoader.load(),500,450);
MusicController musicController = fxmlLoader.getController();
musicController.setStage(stage);
stage.setTitle("Music Player"); stage.setTitle("Music Player");
stage.setScene(scene); stage.setScene(scene);
//TODO: add icon to the stage
stage.show(); stage.show();
} }
+59 -11
View File
@@ -1,31 +1,79 @@
package sbu.javafx; package sbu.javafx;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.event.ActionEvent; import javafx.scene.Scene;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent; import javafx.scene.control.ListView;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class MusicController { public class MusicController {
// TODO: Define your UI components using the @FXML annotation. @FXML
private Label nowPlayingLabel;
//TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. private final ObservableList<String> playlist =
FXCollections.observableArrayList();
private Stage stage;
public void setStage(Stage stage) {
this.stage = stage;
}
@FXML @FXML
public void handlePlayAction() { public void playSong1() {
//Update labels, change button icons, etc. handlePlayAction("Blinding Lights");
} }
//TODO: Logic to add a specific song to the user's playlist. @FXML
public void playSong2() {
handlePlayAction("Shape of You");
}
@FXML
public void playSong3() {
handlePlayAction("Believer");
}
public void handlePlayAction(String songName) {
nowPlayingLabel.setText("Now Playing: " + songName);
}
@FXML
public void addSong1() {
addToPlaylist("Blinding Lights");
}
@FXML
public void addSong2() {
addToPlaylist("Shape of You");
}
@FXML
public void addSong3() {
addToPlaylist("Believer");
}
public void addToPlaylist(String songName) { public void addToPlaylist(String songName) {
//Add the song to a list or update a ListView. 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() { public void openPlaylistWindow() {
//Create a new stage and show the playlist UI.
Label title = new Label("My Playlist");
ListView<String> listView = new ListView<>();
listView.setItems(playlist);
VBox root = new VBox(10);
root.getChildren().addAll(title, listView);
Scene playlistScene = new Scene(root, 400, 300);
stage.setScene(playlistScene);
} }
} }
+42 -2
View File
@@ -1,8 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
<!-- TODO: Add your code here! --> <VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="sbu.javafx.MusicController"
alignment="CENTER"
spacing="15">
<Label text="Music Player"/>
<Label fx:id="nowPlayingLabel"
text="Now Playing: None"/>
<!-- Song 1 -->
<HBox spacing="10" alignment="CENTER">
<Label text="Blinding Lights - The Weeknd - 3:20"/>
<Button text="Play"
onAction="#playSong1"/>
<Button text="Add to Playlist"
onAction="#addSong1"/>
</HBox>
<!-- Song 2 -->
<HBox spacing="10" alignment="CENTER">
<Label text="Shape of You - Ed Sheeran - 4:10"/>
<Button text="Play"
onAction="#playSong2"/>
<Button text="Add to Playlist"
onAction="#addSong2"/>
</HBox>
<!-- Song 3 -->
<HBox spacing="10" alignment="CENTER">
<Label text="Believer - Imagine Dragons - 3:24"/>
<Button text="Play"
onAction="#playSong3"/>
<Button text="Add to Playlist"
onAction="#addSong3"/>
</HBox>
<Button text="View Playlist"
onAction="#openPlaylistWindow"/>
</VBox> </VBox>