forked from AdvancedProgramming1404/HW-07-JavaFX
javafx
This commit is contained in:
@@ -2,7 +2,10 @@ package sbu.javafx;
|
||||
|
||||
import javafx.application.Application;
|
||||
|
||||
public class Launcher{
|
||||
public class Launcher {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) }
|
||||
}
|
||||
Application.launch(MusicApp.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,21 +3,22 @@ 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;
|
||||
|
||||
public class MusicApp extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException
|
||||
{
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
public void start(Stage stage) throws Exception {
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("App-view.fxml"));
|
||||
|
||||
Scene scene = new Scene(loader.load(), 700, 500);
|
||||
|
||||
stage.setTitle("Music Player");
|
||||
|
||||
|
||||
stage.setScene(scene);
|
||||
//TODO: add icon to the stage
|
||||
stage.show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,86 @@
|
||||
package sbu.javafx;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
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 ObservableList<String> playlist =
|
||||
FXCollections.observableArrayList();
|
||||
|
||||
@FXML
|
||||
public void handlePlayAction() {
|
||||
//Update labels, change button icons, etc.
|
||||
public void playSong1() {
|
||||
handlePlayAction("Shape of You");
|
||||
}
|
||||
|
||||
//TODO: Logic to add a specific song to the user's playlist.
|
||||
@FXML
|
||||
public void playSong2() {
|
||||
handlePlayAction("Believer");
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void playSong3() {
|
||||
handlePlayAction("Perfect");
|
||||
}
|
||||
|
||||
public void handlePlayAction(String songName) {
|
||||
nowPlayingLabel.setText("Now Playing: " + songName);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void addSong1() {
|
||||
addToPlaylist("Shape of You");
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void addSong2() {
|
||||
addToPlaylist("Believer");
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void addSong3() {
|
||||
addToPlaylist("Perfect");
|
||||
}
|
||||
|
||||
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 = new Stage();
|
||||
|
||||
VBox root = new VBox(10);
|
||||
|
||||
Label title = new Label("My Playlist");
|
||||
|
||||
ListView<String> listView = new ListView<>();
|
||||
|
||||
listView.setItems(playlist);
|
||||
|
||||
root.getChildren().addAll(title, listView);
|
||||
|
||||
Scene scene = new Scene(root, 300, 400);
|
||||
|
||||
stage.setTitle("Playlist");
|
||||
|
||||
stage.setScene(scene);
|
||||
|
||||
stage.show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user