Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help fixing the errors in this program it runs using javaFX I\'m trying t

ID: 3719021 • Letter: I

Question

I need help fixing the errors in this program it runs using javaFX

I'm trying to figure out how to get this to run and figure how to add music into it.

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<String> 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.

Explanation / Answer

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.Initializable;

import javafx.scene.control.Label;

import javafx.scene.media.Media;

import javafx.scene.media.MediaPlayer;

public class MainController implements Initializable {

@Override

public void initialize(URL location, ResourceBundle resources) {

// TODO Auto-generated method stub

}

@FXML

private Label number;

public void zero(ActionEvent event){

number.setText(number.getText() + "0");

}

public void one(ActionEvent event){

number.setText(number.getText() + "1");

}

public void two(ActionEvent event){

number.setText(number.getText() + "2");

}

public void three(ActionEvent event){

number.setText(number.getText() + "3");

}

public void four(ActionEvent event){

number.setText(number.getText() + "4");

}

public void five(ActionEvent event){

number.setText(number.getText() + "5");

}

public void six(ActionEvent event){

number.setText(number.getText() + "6");

}

public void seven(ActionEvent event){

number.setText(number.getText() + "7");

}

public void eight(ActionEvent event){

number.setText(number.getText() + "8");

}

public void nine(ActionEvent event){

number.setText(number.getText() + "9");

}

public void clear(){

number.setText("");

}

public MediaPlayer track(){

URL[] songs = new URL[]{

getClass().getResource("/res/03. Eyes On Fire.mp3"),

getClass().getResource("/res/05,Graveyard-Endless Night.mp3"),

getClass().getResource("/res/10 Nas - It Ain't Hard To Tell.mp3")

};

final Media media = new Media(songs[Integer.parseInt(number.getText())].toString());

final MediaPlayer mediaplayer = new MediaPlayer(media);

return mediaplayer;

}

public void play(){

track().play();

}

public void stop(){

track().stop();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote