Question: With the program below has a player in the program, but I have my own custom java fx scene that has the same settings. Four

With the program below has a player in the program, but I have my own custom java fx scene that has the same settings. Four buttons (play(named playButton), next(named nextTrack), previous(previousTrack), and stop(stopButton)). It also has a label to display the song name(named songName) and a list view( named playlistViewer). How do I take out the player within this program and how can I add mine own in so it will display my own GUI? Here is my plain text for my GUI, I'm not to good at changing it to a java.

// MP3.java (model class) /** * a class to represent an MP3 song. You can add more features to it, or you can * create an interface 'Song' which contains basic method prototypes like * play(), pause(), stop(), seek() etc and then let the MP3 class implement the * interface if you need. */ public class MP3 { private String songName;//name of song private String songPath;//file path of song //add other attributes here if you like to //default constructor public MP3() { songName = ""; songPath = ""; } //constructor taking song name public MP3(String songName) { this.songName = songName; songPath = ""; } //method stub to demonstrate playing the song public void play() { System.out.println(songName + " song is playing"); } //method stub to demonstrate pausing the song public void pause() { System.out.println(songName + " song is paused"); } //method stub to demonstrate stopping the song public void stop() { System.out.println(songName + " song is stopped"); } //add more methods if you want, like seek() //returns a String containing song info @Override public String toString() { return songName; } } // MP3Player.java (VIEW class) import java.util.ArrayList; import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.scene.text.Text; import javafx.stage.Stage; public class MP3Player extends Application { //Declaring all UI elements ListView songsList; MP3 currentSong; Text currentSongDescription; Button play, previous, next, stop; private double WINDOW_WIDTH = 300, WINDOW_HEIGHT = 300; @Override public void start(Stage primaryStage) throws Exception { //defining all UI components Label label = new Label("Songs List"); songsList = new ListView<>(); //loading some mp3 files (pseudo) songsList.getItems().addAll(loadSomeSongs()); songsList.setMaxHeight(WINDOW_HEIGHT / 2); currentSong = null; currentSongDescription = new Text(); play = new Button("Play"); previous = new Button("Previous"); next = new Button("Next"); stop = new Button("Stop"); //adding all buttons into an HBox (horizontal) HBox buttons = new HBox(play, previous, next, stop); buttons.setAlignment(Pos.CENTER); //aligning center buttons.setSpacing(20); //space between each button //adding all rows into a VBox (vertical ordering) VBox rows = new VBox(label, songsList, currentSongDescription, buttons); rows.setAlignment(Pos.CENTER); rows.setSpacing(20); /** * creating a Pane, defining a scene and setting the scene to the stage, * and showing it */ Pane pane = new Pane(rows); Scene scene = new Scene(pane); primaryStage.setScene(scene); primaryStage.setTitle("MP3 Player"); primaryStage.show(); //adding event listeners songsList.getSelectionModel().selectedItemProperty().addListener(e -> { //updating selected song currentSong = songsList.getSelectionModel().getSelectedItem(); currentSongDescription.setText("Current song: " + currentSong.toString()); }); play.setOnAction(e -> { //playing current song if (currentSong != null) { currentSong.play(); } }); stop.setOnAction(e -> { //stopping current song if (currentSong != null) { currentSong.stop(); } }); next.setOnAction(e -> { //selecting next song songsList.getSelectionModel().selectNext(); }); previous.setOnAction(e -> { //selecting previous song songsList.getSelectionModel().selectPrevious(); }); } //method to load an array list with some test MP3 objects and return it public ArrayList loadSomeSongs() { ArrayList mp3List = new ArrayList<>(); //Adding some MP3 objects mp3List.add(new MP3("Song of Ice and Fire")); mp3List.add(new MP3("Rains of Castamere")); mp3List.add(new MP3("Light of the Seven")); mp3List.add(new MP3("Dancing Dragons")); mp3List.add(new MP3("Heart of a Warrior")); return mp3List; } public static void main(String[] args) { launch(args); }}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!