below is my current code for a math game i'm having problems creating the answer checking part of it, any assistance is appreciated.
import javax.swing.*;
import java.util.Random;
import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.event.*;
import javax.swing.*;
public class MathPanel extends JPanel {
// Declares Labels and Buttons
public JButton AddButt , SubButt , MultiButt , DivideButt , Submit ;
public JTextField Answer ;
public JLabel Select , Result , Counter ,ImgLbl, Question ;
int CountR , CountW;
public MathPanel(){
// Sets Up the Gui interface
ImageIcon icon = new ImageIcon ("blank.png");
ImageIcon icon1 = new ImageIcon ("sad.png");
ImageIcon icon2 = new ImageIcon ("happy.png");
setPreferredSize (new Dimension(300, 400));
setBackground (Color.WHITE);
Select = new JLabel ("Choose Your Question Type:");
Question= new JLabel ("Question Is Yet To Be Generated");
Result = new JLabel ("Submit Your Answer When You Are Ready");
ImgLbl = new JLabel (icon);
Counter= new JLabel ("Right:" + CountR + " & Wrong :" + CountW);
AddButt = new JButton ("Add");
SubButt = new JButton ("Subtract");
MultiButt = new JButton ("Multiply");
DivideButt = new JButton ("Divide");
Submit = new JButton ("Submit");
//creates listeners to spawn questions when buttons are clicked
AddButt.addActionListener(new TempListener());
SubButt.addActionListener(new TempListener());
MultiButt.addActionListener(new TempListener());
DivideButt.addActionListener(new TempListener());
Answer = new JTextField(10);
Answer.addActionListener(new TempListener());
Submit.addActionListener(new AnswerListener());
//puts the buttons and labels on the gui
add (Select);
add (AddButt);
add (SubButt);
add (MultiButt);
add (DivideButt);
add (Question);
add (Answer);
add (Submit);
add (Counter);
add (Result);
add (ImgLbl);
}
private class TempListener implements ActionListener{
int R1 , R2 ;
Random generator= new Random();
public void actionPerformed(ActionEvent Event) {
if (Event.getSource()==(AddButt)){
R1 = generator.nextInt(10)+1;
R2 = generator.nextInt(10)+1;
Question.setText(R1 + "+" + R2) ;
}
if (Event.getSource()==(SubButt)){
R1 = generator.nextInt(10)+1;
R2 = generator.nextInt(10)+1;
Question.setText(R1 + "-" + R2) ;
}
if (Event.getSource()==(MultiButt)){
R1 = generator.nextInt(10)+1;
R2 = generator.nextInt(10)+1;
Question.setText(R1 + "*" + R2) ;
}
if (Event.getSource()==(DivideButt)){
R1 = generator.nextInt(10)+1;
R2 = generator.nextInt(10)+1;
Question.setText(R1 + "/" + R2) ;
}