Question: finsh the method Use a pop up to ask the user the question If the answer is correct Increase the score by the prizeMoney Call

finsh the method Use a pop up to ask the user the question If the answer is correct Increase the score by the prizeMoney Call the updateScore() method Pop up a message to tell the user they were correct Otherwise Decrement the score by the prizeMoney Pop up a message to tell the user the correct answer Call the updateScore() method.must compile and run

import java.applet.AudioClip;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Component;

import java.awt.GridLayout;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.net.URL;

import java.util.LinkedList;

import javax.sound.sampled.AudioInputStream;

import javax.sound.sampled.AudioSystem;

import javax.sound.sampled.Clip;

import javax.swing.BoxLayout;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JApplet;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

/* This recipe is to be used with the Jeopardy Handout: http://bit.ly/1bvnvd4 */

public class Jeopardy implements ActionListener {

private JButton firstButton;

private JButton secondButton;

private JButton thirdButton, fourthButton;

LinkedList buttonList =new LinkedList();

private JPanel quizPanel;

int score = 0;

JLabel scoreBox = new JLabel("0");

int buttonCount = 0;

public static void main(String[] args) {

new Jeopardy().start();

}

private void start() {

JFrame frame = new JFrame();

quizPanel = new JPanel();

frame.setLayout(new BorderLayout());

frame.setVisible(true);

frame.setTitle("Jeopardy");

JPanel panel = createHeader("Quantum Physics");

quizPanel.add(panel);

frame.add(quizPanel);

firstButton = createButton("$100");

quizPanel.add(firstButton);

secondButton = createButton("$200");

quizPanel.add(secondButton);

firstButton.addActionListener(this);

secondButton.addActionListener(this);

buttonList.add(firstButton);

buttonList.add(secondButton);

buttonList.add(thirdButton);

buttonList.add(fourthButton);

frame.pack();

quizPanel.setLayout(new GridLayout(buttonCount + 1, 3));

frame.add(makeScorePanel(), BorderLayout.NORTH);

frame.setSize(Toolkit.getDefaultToolkit().getScreenSize().height,

Toolkit.getDefaultToolkit().getScreenSize().width);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

/*

* 13. Use the method provided to play the Jeopardy theme music

*

* 14. Add buttons so that you have $200, $400, $600, $800 and $1000

* questions

*

* [optional] Use the showImage or playSound methods when the user answers a

* question [optional] Add new topics for the quiz

*/

private JButton createButton(String dollarAmount) {

JButton button = new JButton("");

button.setText(dollarAmount);

buttonCount++;

return button;

}

public void actionPerformed(ActionEvent arg0) {

// Remove this temporary message:

JOptionPane

.showMessageDialog(null,

"pressed " + ((JButton) arg0.getSource()).getText()

+ " button");

// Use the method that plays the jeopardy theme music.

JButton buttonPressed = (JButton) arg0.getSource();

// If the buttonPressed was the firstButton

if (buttonPressed == firstButton) {

askQuestion("How many dimensions are there?", "11", 100);

}

// Call the askQuestion() method

// Fill in the askQuestion() method. When you play the game, the score

// should change.

// Or if the buttonPressed was the secondButton

// Call the askQuestionRecipe with a harder question

// Clear the button text (set the button text to nothing)

}

private void askQuestion(String question, String correctAnswer,

int prizeMoney) {

JOptionPane.showMessageDialog(null,

question);

// Use a pop up to ask the user the question

// If the answer is correct

// Increase the score by the prizeMoney

// Call the updateScore() method

// Pop up a message to tell the user they were correct

// Otherwise

// Decrement the score by the prizeMoney

// Pop up a message to tell the user the correct answer

// Call the updateScore() method

}

public void playJeopardyTheme() {

try {

AudioInputStream audioInputStream = AudioSystem

.getAudioInputStream(new URL(

"C:/Users/611137126/desktop/chegg/Jeopardyjeopardy.wav?raw=true"));

Clip clip = AudioSystem.getClip();

clip.open(audioInputStream);

clip.start();

} catch (Exception ex) {

ex.printStackTrace();

}

}

private void playSound(String fileName) {

AudioClip scream = JApplet.newAudioClip(getClass()

.getResource(fileName));

scream.play();

}

private Component makeScorePanel() {

JPanel panel = new JPanel();

panel.add(new JLabel("score:"));

panel.add(scoreBox);

panel.setBackground(Color.CYAN);

return panel;

}

private void updateScore() {

scoreBox.setText("" + score);

}

private JPanel createHeader(String topicName) {

JPanel panelj = new JPanel();

panelj.setLayout(new BoxLayout(panelj, BoxLayout.PAGE_AXIS));

JLabel l1 = new JLabel(topicName);

l1.setAlignmentX(Component.CENTER_ALIGNMENT);

panelj.add(l1);

return panelj;

}

void showCorrectImage() {

showImage("correct.jpg");

}

void showIncorrectImage() {

showImage("incorrect.jpg");

}

private void showImage(String fileName) {

JFrame frame = new JFrame();

URL imageURL = getClass().getResource(fileName);

Icon icon = new ImageIcon(imageURL);

JLabel image = new JLabel(icon);

frame.add(image);

frame.setVisible(true);

frame.pack();

}

}

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!