HW7
This commit is contained in:
@@ -2,30 +2,68 @@ package sbu.javafx;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.event.ActionEvent;
|
||||
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 javafx.geometry.Pos;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MusicController {
|
||||
|
||||
// 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.
|
||||
@FXML
|
||||
private Label nowPlayingLabel;
|
||||
|
||||
@FXML
|
||||
public void handlePlayAction() {
|
||||
//Update labels, change button icons, etc.
|
||||
private VBox rootContainer;
|
||||
|
||||
private static ArrayList<String> playlist = new ArrayList<>();
|
||||
|
||||
@FXML
|
||||
public void handlePlayAction(ActionEvent event) {
|
||||
Button clickedButton = (Button) event.getSource();
|
||||
String songName = (String) clickedButton.getUserData();
|
||||
nowPlayingLabel.setText("Now Playing: " + songName);
|
||||
}
|
||||
|
||||
//TODO: Logic to add a specific song to the user's playlist.
|
||||
@FXML
|
||||
public void handleAddAction(ActionEvent event) {
|
||||
Button clickedButton = (Button) event.getSource();
|
||||
String songName = (String) clickedButton.getUserData();
|
||||
addToPlaylist(songName);
|
||||
}
|
||||
|
||||
public void addToPlaylist(String songName) {
|
||||
//Add the song to a list or update a ListView.
|
||||
if (!playlist.contains(songName)) {
|
||||
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() {
|
||||
//Create a new stage and show the playlist UI.
|
||||
Stage stage = (Stage) rootContainer.getScene().getWindow();
|
||||
|
||||
ListView<String> listView = new ListView<>();
|
||||
listView.getItems().addAll(playlist);
|
||||
|
||||
Button backButton = new Button("Back");
|
||||
backButton.setOnAction(e -> {
|
||||
try {
|
||||
javafx.fxml.FXMLLoader fxmlLoader = new javafx.fxml.FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), 800, 600);
|
||||
stage.setScene(scene);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
VBox vbox = new VBox(15, new Label("Your Playlist"), listView, backButton);
|
||||
vbox.setAlignment(Pos.CENTER);
|
||||
vbox.setStyle("-fx-padding: 30px;");
|
||||
|
||||
Scene playlistScene = new Scene(vbox, 800, 600);
|
||||
stage.setScene(playlistScene);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user