Question: I need help with combining these two programs together. I have to combine my file chooser program and my java fx program. Can someone with

I need help with combining these two programs together. I have to combine my file chooser program and my java fx program. Can someone with this please? I've tried everything. Here's the code I have.... //The file chooser import java.net.URL; import java.util.concurrent.CountDownLatch; import java.util.logging.Level; import java.util.logging.Logger; import javafx.embed.swing.JFXPanel; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import javax.swing.JFileChooser; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileNameExtensionFilter; public class MyMp3{ public static void main(String[] args){ new MyMp3().start(); } public void start(){ String fileName = null; URL url; final CountDownLatch latch = new CountDownLatch(1); SwingUtilities.invokeLater(new Runnable(){ public void run() { new JFXPanel(); // initializes JavaFX environment latch.countDown(); } }); try { latch.await(); } catch (InterruptedException ex){ Logger.getLogger(MyMp3.class.getName()).log(Level.SEVERE, null, ex); } JFileChooser audio = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( "MP3 Files", "mp3"); audio.setFileFilter(filter); int returnVal = audio.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { fileName = audio.getSelectedFile().toURI().toString(); } MediaPlayer mediaPlayer; mediaPlayer = new MediaPlayer(new Media(fileName)); mediaPlayer.play(); } } //Here is my java fx program public class MP3 { private String trackName; private String trackPath; public MP3() { trackName = ""; trackPath = ""; } public MP3(String trackName) { this.trackName = trackName; trackPath = ""; } public void play() { System.out.println(trackName + " song is playing"); } public void stop() { System.out.println(trackName + " song is stopped"); } @Override public String toString() { return trackName; } } import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class MP3PlayerGui extends Application { public void start(Stage stage) throws Exception { Parent parent = FXMLLoader.load(getClass().getResource("FinalProject.fxml")); Scene scene = new Scene(parent); stage.setTitle("MP3 Player"); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } } import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListView; public class PleaseProvideControllerClassName { @FXML private Button playButton; @FXML private Button stopButton; @FXML private Label songName; @FXML private ListView playlistViewer; @FXML private Button nextTrack; @FXML private Button previousTrack; } import java.util.ArrayList; import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.collections.FXCollections; public class MP3Player { //ListView songsList; MP3 currentSong; Text currentSongDescription; // Button playButton, previousTrack, nextTrack, stopButton; @FXML private Button playButton; @FXML private Button stopButton; @FXML private Label songName; @FXML private ListView playlistViewer; @FXML private Button nextTrack; @FXML private Button previousTrack; // @Override public void initialize() // start(Stage primaryStage) throws Exception { playlistViewer.setItems(FXCollections.observableArrayList( loadSomeSongs() ) ); // songsList.getItems().addAll(loadSomeSongs()); currentSong = null; currentSongDescription = new Text(); playlistViewer.getSelectionModel().selectedItemProperty().addListener(e -> { currentSong = playlistViewer.getSelectionModel().getSelectedItem(); currentSongDescription.setText("Current song: " + currentSong.toString()); }); playButton.setOnAction(e -> { if (currentSong != null) { currentSong.play(); } }); stopButton.setOnAction(e -> { if (currentSong != null) { currentSong.stop(); } }); nextTrack.setOnAction(e -> { playlistViewer.getSelectionModel().selectNext(); }); previousTrack.setOnAction(e -> { playlistViewer.getSelectionModel().selectPrevious(); }); } public ArrayList loadSomeSongs() { ArrayList mp3List = new ArrayList<>(); 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); // } } Thank for the help in advance.

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!