import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.ArrayList; public class GUI extends JFrame implements ActionListener { JMenuItem resetItem, startItem; JTextField ansTextField; JLabel resultLabel, score

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

please build up the java code
complete the code and fill up missing codes
// = needs input for the code
thank you


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;

public class GUI extends JFrame implements ActionListener {
JMenuItem resetItem, startItem;
JTextField ansTextField;
JLabel resultLabel, scoreLabel, timeLabel, operationLabel;
Timer timer;
DoubleDigitOp op;
final int maxTime = 6;
final int runTime = 100;
double score = 0;
int newTime = maxTime*runTime;
String[] status = new String[]{"Score: ","Timer: "};
String[] reset = new String[]{"Score: 0.00","Timer: "+((double)newTime/100),
"00 + 00 = ","Game Message"};
public GUI(String title){
setTitle(title);
//Create a Menu names "Game" (1)
//Add two menus on "Game": the menus named "Start" and "Reset" (6) -- both execute an action
JMenuBar menuBar = new JMenuBar();
menuBar.add(gameMenu);
setJMenuBar(menuBar);
JPanel content = new JPanel();
content.setLayout(new BorderLayout());
JPanel statusPanel = new JPanel();
statusPanel.setLayout(new FlowLayout());
scoreLabel = new JLabel(reset[0]); //contains the current score
statusPanel.add(scoreLabel);
timeLabel = new JLabel(reset[1]); //contains the remaining time
statusPanel.add(timeLabel);
content.add(statusPanel,BorderLayout.NORTH);
JPanel opsPanel = new JPanel();
opsPanel.setLayout(new FlowLayout());
operationLabel = new JLabel(reset[2]); //contains the operation, e.g. x + y
opsPanel.add(operationLabel);
ansTextField = new JTextField(10); //a text field where thew user orplayer enter the answer
ansTextField.addActionListener(this);
ansTextField.requestFocus();
ansTextField.setBackground(Color.LIGHT_GRAY);
opsPanel.add(ansTextField);
content.add(opsPanel,BorderLayout.CENTER);
//the resulLabel contains the current situation in the game
resultLabel = new JLabel(reset[3],SwingConstants.CENTER);
content.add(resultLabel,BorderLayout.SOUTH);
setContentPane(content);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(30,10);
setVisible(true);
}
public static void main(String[] args){
//write the appropriate command here (1)
}
public void actionPerformed(ActionEvent e){
if(){ //chooses to reset the game, write the correct condition (1)
//resets the answer, score, timer, operations, and result (1)
} else if(){ //chooses to start the game, write the correct condition (1)
start();
} else if(e.getSource()==ansTextField){ //when the user presses enter on the answer text field
if(){ //this is where the answer is correct, write the correct condition (1)
//print "Correct" on the result (1)
score += (double)newTime/runTime;
scoreLabel.setText(status[0]+score);
start();
} else {
resetMany(1,5);
//print "Incorrect" on the result (1)
}
} else if(e.getSource()==timer){
newTime--;
timeLabel.setText(status[1]+((double)newTime/runTime));
if(newTime==0){
resetMany(1,5);
resultLabel.setText("Time's Up!");
}
} else;
}
public void resetMany(int ... choices){
for(int choice: choices){
resetOne(choice);
}
}
public void resetOne(int choice){
if(choice == 4){
ansTextField.setText("");
} else if(choice == 0){
scoreLabel.setText(reset[0]);
score = 0;
} else if(choice == 1){
timeLabel.setText(reset[1]);
newTime = maxTime*runTime;
} else if(choice == 2){
operationLabel.setText(reset[2]);
} else if(choice == 3){
resultLabel.setText(reset[3]);
} else {
if(timer!=null){
timer.stop();
}
}
}
public void resetAll(){
ansTextField.setText("");
scoreLabel.setText(reset[0]);
score = 0;
timeLabel.setText(reset[1]);
newTime = maxTime*runTime;
operationLabel.setText(reset[2]);
resultLabel.setText(reset[3]);
if(timer!=null){
timer.stop();
}
}
public void start(){
//reset time and answer textfield (1)
//print the operation to the operationLLabel (1) -- e.g. x + y =
timer = new Timer(10,this);
timer.start();
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education