finishing controller and fxml hotfix

This commit is contained in:
2026-07-17 01:10:10 +03:30
parent ef9c4cebcc
commit 58536d2bce
2 changed files with 76 additions and 22 deletions
+56 -12
View File
@@ -1,31 +1,75 @@
package sbu.javafx;
import javafx.fxml.FXML;
import javafx.collections.FXCollections;
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.control.ListView;
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.
@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 ArrayList<String> playlist = new ArrayList<>();
@FXML
public void handlePlayAction() {
//Update labels, change button icons, etc.
}
public void handlePlayAction(ActionEvent event) {
Button button = (Button) event.getSource();
String songName = "";
switch (button.getId()) {
case "play1":
songName = "Blinding Lights";
break;
case "play2":
songName = "Shape of You";
break;
case "play3":
songName = "Believer";
break;
}
//TODO: Logic to add a specific song to the user's playlist.
nowPlayingLabel.setText("Now Playing: " + 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 addSong1() {
addToPlaylist("Blinding Lights");
}
@FXML
public void addSong2() {
addToPlaylist("Shape of You");
}
@FXML
public void addSong3() {
addToPlaylist("Believer");
}
@FXML
public void openPlaylistWindow() {
//Create a new stage and show the playlist UI.
Stage stage = new Stage();
ListView<String> listView = new ListView<>();
listView.setItems(FXCollections.observableArrayList(playlist));
VBox root = new VBox(10);
root.getChildren().addAll(new Label("Playlist"), listView);
stage.setScene(new Scene(root, 300, 250));
stage.setTitle("Playlist");
stage.show();
}
}
}