import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.be
ID: 3718015 • Letter: I
Question
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
import java.io.*;
public class JPanelBrandywine extends JPanel implements ActionListener {
JLabel jlBrandywine, jlInstructions;
JButton jbQuestion, jbAnswer1, jbAnswer2, jbAnswer3, jbAnswer4, jbScore, jbNext, currButton, buttonUpdate, jbBack;
String theme, difficulty;
Integer roundCount, brandywineScore, totalScore;
XMLEncoder xe;
XMLDecoder de;
public JPanelBrandywine(String infTheme, String infDifficulty) {
super();
setLayout(null);
theme = infTheme;
difficulty = infDifficulty;
brandywineScore = 0;
roundCount = 0;
jlBrandywine = new JLabel("Brandywine");
jlBrandywine.setBounds(new Rectangle(300, 20, 220, 20));
add(jlBrandywine);
jlInstructions = new JLabel("Click the correct answer for points");
jlInstructions.setBounds(new Rectangle(240, 50, 220, 20));
add(jlInstructions);
jbScore = new JButton("Score: " + brandywineScore);
jbScore.setBounds(new Rectangle(250, 110, 120, 40));
add(jbScore);
jbQuestion = new JButton();
jbQuestion.setBounds(new Rectangle(110, 180, 400, 40));
add(jbQuestion);
jbAnswer1 = new JButton();
jbAnswer1.setBounds(new Rectangle(35, 250, 250, 40));
jbAnswer1.addActionListener(this);
add(jbAnswer1);
jbAnswer2 = new JButton();
jbAnswer2.setBounds(new Rectangle(330, 250, 250, 40));
jbAnswer2.addActionListener(this);
add(jbAnswer2);
jbAnswer3 = new JButton();
jbAnswer3.setBounds(new Rectangle(35, 300, 250, 40));
jbAnswer3.addActionListener(this);
add(jbAnswer3);
jbAnswer4 = new JButton();
jbAnswer4.setBounds(new Rectangle(330, 300, 250, 40));
jbAnswer4.addActionListener(this);
add(jbAnswer4);
if (theme.equals("programming")) {
if (difficulty.equals("easy")) {
jbQuestion.setText("Which of these is an integer?");
jbAnswer1.setText("X");
jbAnswer2.setText("4");
jbAnswer3.setText("7.9");
jbAnswer4.setText("JButton");
validate();
repaint();
}
if (difficulty.equals("medium")) {
jbQuestion.setText("What does a timer do?");
jbAnswer1.setText("Keep track of minutes");
jbAnswer2.setText("Generate actions at set intervals");
jbAnswer3.setText("Look pretty");
jbAnswer4.setText("Keep track of seconds");
validate();
repaint();
}
if (difficulty.equals("hard")) {
jbQuestion.setText("Which is used to create a circle?");
jbAnswer1.setText("drawCircle");
jbAnswer2.setText("drawOval");
jbAnswer3.setText("fillCircle");
jbAnswer4.setText("DrawOval");
validate();
repaint();
}
}
if (theme.equals("football")) {
if (difficulty.equals("easy")) {
jbQuestion.setText("How many feet are in a football field?");
jbAnswer1.setText("50");
jbAnswer2.setText("100");
jbAnswer3.setText("300");
jbAnswer4.setText("400");
validate();
repaint();
}
if (difficulty.equals("medium")) {
jbQuestion.setText("How many points is a field goal worth?");
jbAnswer1.setText("2");
jbAnswer2.setText("5");
jbAnswer3.setText("3");
jbAnswer4.setText("6");
validate();
repaint();
}
if (difficulty.equals("hard")) {
jbQuestion.setText("What type of play is a deep high pass?");
jbAnswer1.setText("Play Action");
jbAnswer2.setText("Screen Pass");
jbAnswer3.setText("Hail Mary");
jbAnswer4.setText("Toss");
validate();
repaint();
}
}
if (theme.equals("math")) {
if (difficulty.equals("easy")) {
jbQuestion.setText("Which of these equations is correct?");
jbAnswer1.setText("5x5 = 30");
jbAnswer2.setText("20/4 = 6");
jbAnswer3.setText("9+8 = 16");
jbAnswer4.setText("25-13 = 12");
validate();
repaint();
}
if (difficulty.equals("medium")) {
jbQuestion.setText("Which of these equations is correct?");
jbAnswer1.setText("5x3 = 20");
jbAnswer2.setText("20/8 = 2");
jbAnswer3.setText("9+10 = 20");
jbAnswer4.setText("58-21 = 37");
validate();
repaint();
}
if (difficulty.equals("hard")) {
jbQuestion.setText("Which of these equations is correct?");
jbAnswer1.setText("8x8 = 60");
jbAnswer2.setText("100/5 = 30");
jbAnswer3.setText("25+26 = 51");
jbAnswer4.setText("102-71 = 31");
validate();
repaint();
}
}
narrate their code walkthrough of the frozen code submission. should spend at least a few minutes explaining facets of the project, with an emphasis on the Java used. Suggestions Java Code Class structure The Timer XML Game Over The Theme Please explain the code for me using xml or anything thank you
Explanation / Answer
Explained everything in the code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
import java.io.*;
public class JPanelBrandywine extends JPanel implements ActionListener {
JLabel jlBrandywine, jlInstructions;
JButton jbQuestion, jbAnswer1, jbAnswer2, jbAnswer3, jbAnswer4, jbScore, jbNext, currButton, buttonUpdate, jbBack;
String theme, difficulty;
Integer roundCount, brandywineScore, totalScore;
XMLEncoder xe;
XMLDecoder de;
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new JPanelBrandywine("programming", "easy"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 800);
frame.setVisible(true);
}
public JPanelBrandywine(String infTheme, String infDifficulty) {
// Call constructor of susper class. Needed
super();
// Set layout to null (this will not show anything)
setLayout(null);
// Set field variables
theme = infTheme;
difficulty = infDifficulty;
brandywineScore = 0;
roundCount = 0;
// Create new JLabel
jlBrandywine = new JLabel("Brandywine");
jlBrandywine.setBounds(new Rectangle(300, 20, 220, 20));
// Add JLabel to JPanel
add(jlBrandywine);
// Create more JLabels/JButtons and add to JPanel
jlInstructions = new JLabel("Click the correct answer for points");
jlInstructions.setBounds(new Rectangle(240, 50, 220, 20));
add(jlInstructions);
jbScore = new JButton("Score: " + brandywineScore);
jbScore.setBounds(new Rectangle(250, 110, 120, 40));
add(jbScore);
jbQuestion = new JButton();
jbQuestion.setBounds(new Rectangle(110, 180, 400, 40));
add(jbQuestion);
jbAnswer1 = new JButton();
jbAnswer1.setBounds(new Rectangle(35, 250, 250, 40));
// What will happen if the button is clicked. This interface (this class implements ActionListener) will be used
jbAnswer1.addActionListener(this);
add(jbAnswer1);
jbAnswer2 = new JButton();
jbAnswer2.setBounds(new Rectangle(330, 250, 250, 40));
jbAnswer2.addActionListener(this);
add(jbAnswer2);
jbAnswer3 = new JButton();
jbAnswer3.setBounds(new Rectangle(35, 300, 250, 40));
jbAnswer3.addActionListener(this);
add(jbAnswer3);
jbAnswer4 = new JButton();
jbAnswer4.setBounds(new Rectangle(330, 300, 250, 40));
jbAnswer4.addActionListener(this);
add(jbAnswer4);
// If theme is about programming
if (theme.equals("programming")) {
// If difficulty is easy
if (difficulty.equals("easy")) {
// Set these texts to the JLabels and JButtons
jbQuestion.setText("Which of these is an integer?");
jbAnswer1.setText("X");
jbAnswer2.setText("4");
jbAnswer3.setText("7.9");
jbAnswer4.setText("JButton");
// Any changes happen to view elements, it validate() needs to be called. It will update the view in the layout
validate();
// Repaint the elements in the layout
repaint();
}
// All same as above
if (difficulty.equals("medium")) {
jbQuestion.setText("What does a timer do?");
jbAnswer1.setText("Keep track of minutes");
jbAnswer2.setText("Generate actions at set intervals");
jbAnswer3.setText("Look pretty");
jbAnswer4.setText("Keep track of seconds");
validate();
repaint();
}
if (difficulty.equals("hard")) {
jbQuestion.setText("Which is used to create a circle?");
jbAnswer1.setText("drawCircle");
jbAnswer2.setText("drawOval");
jbAnswer3.setText("fillCircle");
jbAnswer4.setText("DrawOval");
validate();
repaint();
}
}
if (theme.equals("football")) {
if (difficulty.equals("easy")) {
jbQuestion.setText("How many feet are in a football field?");
jbAnswer1.setText("50");
jbAnswer2.setText("100");
jbAnswer3.setText("300");
jbAnswer4.setText("400");
validate();
repaint();
}
if (difficulty.equals("medium")) {
jbQuestion.setText("How many points is a field goal worth?");
jbAnswer1.setText("2");
jbAnswer2.setText("5");
jbAnswer3.setText("3");
jbAnswer4.setText("6");
validate();
repaint();
}
if (difficulty.equals("hard")) {
jbQuestion.setText("What type of play is a deep high pass?");
jbAnswer1.setText("Play Action");
jbAnswer2.setText("Screen Pass");
jbAnswer3.setText("Hail Mary");
jbAnswer4.setText("Toss");
validate();
repaint();
}
}
if (theme.equals("math")) {
if (difficulty.equals("easy")) {
jbQuestion.setText("Which of these equations is correct?");
jbAnswer1.setText("5x5 = 30");
jbAnswer2.setText("20/4 = 6");
jbAnswer3.setText("9+8 = 16");
jbAnswer4.setText("25-13 = 12");
validate();
repaint();
}
if (difficulty.equals("medium")) {
jbQuestion.setText("Which of these equations is correct?");
jbAnswer1.setText("5x3 = 20");
jbAnswer2.setText("20/8 = 2");
jbAnswer3.setText("9+10 = 20");
jbAnswer4.setText("58-21 = 37");
validate();
repaint();
}
if (difficulty.equals("hard")) {
jbQuestion.setText("Which of these equations is correct?");
jbAnswer1.setText("8x8 = 60");
jbAnswer2.setText("100/5 = 30");
jbAnswer3.setText("25+26 = 51");
jbAnswer4.setText("102-71 = 31");
validate();
repaint();
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO: perform action on click of a button
System.out.println(e);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.