I want to use this class and method with all of my buttons and text fields. My program contains 1 push button that adds questions and answers to a
test, 2nd button that starts a test, a 3rd button that scores the test, and a text field that enters the user information. How would this work? I know how to create questions and answers, start a test, and score a test it's just a matter of how to implement the button and text fields. I'll post the code that I have done so far. This is my final exam and it looks like a real fun project and learning experience. I really would like your input on this program. I have no shot of failing the class even if I bomb this final, but it's a learning thing to me.
Please see:private class ButtonListener implements ActionListener{
public void actionPerformed (ActionEvent event)
with all of my buttons and text fields.
Driver Program
_________________________________________________________________________________
import javax.swing.JFrame;
public class TestingDriver
{
//-----------------------------------------------------------------
// Creates and displays the main program frame.
//-----------------------------------------------------------------
public static void main (
String[] args)
{
JFrame frame = new JFrame ("Testing Program");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
TestingPanel panel = new TestingPanel();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}
Class Program
____________________________________________________________________________-_______
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestingPanel extends JPanel
{
private JButton addButton, testButton, scoreButton;
private JTextField ts;
private JLabel addQuestionAnswerLabel, questionAnswerLabel, scoreLabel, resultAddQuestionLabel, resultQuestionAnswerLabel, resultScoreLabel;
//-----------------------------------------------------------------
// Constructor: Sets up the GUI.
//-----------------------------------------------------------------
public TestingPanel()
{
addButton = new JButton ("Add Question/Test");//Button to add questions and answers
addButton.addActionListener (new ButtonListener());//Add question and answer button to action listener
testButton = new JButton ("Start Test");//Test button to start the test
testButton.addActionListener (new ButtonListener());//button to action listener
scoreButton = new JButton ("Score Test");//Score test button
scoreButton.addActionListener (new ButtonListener());score button to action listener//Add the score button to the action listener
addQuestionAnswerLabel = new JLabel ("Input for Question and Answer are accepted:");//Label that says display the questions and answers entered
resultAddQuestionLabel = new JLabel ();//Label that the question and answer were entered
questionAnswerLabel = new JLabel ("Your test questions and answers will start now:");//Label that says the test will start
resultQuestionAnswerLabel = new JLabel ();//Questions and answers displayed in the test
scoreLabel = new JLabel ("Your score is:");//Label that says the score
resultScoreLabel = new JLabel ();//Results of the score label
ts = new JTextField(200);//Create 200 field text field
ts.addActionListener (new ButtonListener());//Add text field to the action listener
add (ts);//add to panel
add (addButton);//add to panel
add (testButton);//add to panel
add (scoreButton);//add to panel
add (addQuestionAnswerLabel);//add to panel
add (resultAddQuestionLabel);//add to panel
add (questionAnswerLabel);//add to panel
add (resultQuestionAnswerLabel);//add to panel
add (scoreLabel);//add to panel
add (resultScoreLabel);//add to panel
setBackground (Color.cyan);
setPreferredSize (new Dimension(300, 500));
}
//Button Listener Class implements Action Listener
private class ButtonListener implements ActionListener{
//Method to accept action events
public void actionPerformed (ActionEvent event)
{
}
}
}
1. Create a program named Testing that it will:
• Uses a GUI interface with three buttons.
• The first button will allow an instructor to add questions and answers to a test and store the questions in a file named Test.txt. (If you would like two separate files one for tests and one for answers that will be ok, name the second file Answers.txt).
• The second button will allow a student to take a test. It will display the question and accept input from the student user. It should write answers to a file named Responses.txt.
• The third button will score the test by comparing the answers in the Responses.txt file to the answers in the Test.txt file (or the Answers.txt file if you choose that route)
• The display for the third button should output the question #, the question and answers to the screen. A score should be generated based on whether the question was accurate or inaccurate (in this case you don’t have to check to see if it was close, if the answer was exact then give it points, if not give it zero points.)
• Use approximately 5 questions for test data.
2. User inputs the following data:
Command button (Create Test, Take Test, Score Test)
Display accepts user input and stores to a file
3. User receives the following output to the screen:
Assessment type
Question #
Points assigned 2 per question
Question
Correct Answer
Sample GUI
Sample Output