Question: JukeBox.java import static javafx.application.Application.launch; import java.io.File; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.layout.HBox; import
JukeBox.java
import static javafx.application.Application.launch; import java.io.File; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.media.AudioClip; import javafx.stage.Stage;
/** * This is your assignment. make sure * that this works without error * @author Dr. Jupiter */ public class JukeBox extends Application { private ChoiceBox choice; private AudioClip[] tunes; private AudioClip current; private Button playButton, stopButton; //----------------------- // presents an interface that allows the user to select and play // a tune from a drop down box //----------------------- @Override public void start(Stage primaryStage) { String [] names = { "Western Beats", "Classical Melody", "Jeapordy Theme", "eightiesJam", "New Age Rhythm", "lullaby", "hitchcock" }; // need to populate this list with the name of the songs // that you want to use in this jukebox // works with .wav and .mp3 file extensions File [] audioFiles = {new File("westernBeat.wav"), new File("classical.wav"), new File("jeapordy.mp3"), new File("eightiesJam.wav"), new File("New Age Rhythm.wav"), new File("lullaby.mp3"), new File("hitchcock.wav") }; tunes = new AudioClip[audioFiles.length]; for(int i = 0; i < audioFiles.length; i++) { tunes[i] = new AudioClip(audioFiles[i].toURI().toString()); } current = tunes[0]; Label label = new Label("Select a tune: "); choice = new ChoiceBox<>(); choice.getItems().addAll(names); choice.getSelectionModel().selectFirst(); choice.setOnAction(this::processChoice); playButton = new Button("Play :) "); stopButton = new Button("Stop :( "); HBox buttons = new HBox(playButton, stopButton); buttons.setSpacing(10); buttons.setPadding(new Insets(15, 0, 0, 0)); buttons.setAlignment(Pos.CENTER); playButton.setOnAction(this::processButtonPush); stopButton.setOnAction(this::processButtonPush); VBox root = new VBox(label, choice, buttons); root.setPadding(new Insets(15, 15, 15, 25)); root.setSpacing(10); root.setStyle("-fx-background-color: skyblue"); Scene scene = new Scene(root, 300, 150); primaryStage.setTitle("Java Jupiter JukeBox"); primaryStage.setScene(scene); primaryStage.show(); } // ------------------------- // When a choice box selection is made3, stops current clip // if one was playing, and sets the current tune //-------------------------- public void processChoice(ActionEvent event) { current.stop(); current = tunes[choice.getSelectionModel().getSelectedIndex()]; } //---------------------------- // handles the play and stop buttons. Stops the current clip // in either case. If the play button was pressed. , restarts the // current clip //---------------------------- public void processButtonPush(ActionEvent event) { current.stop(); if(event.getSource() == playButton) { current.play(); } } /* public static void main(String [] args) { launch(args); } */ }
I'm trying to figure out how to get this to run and figure how to add music into it.