Trying to make my first Swing GUI but stuff's forgeted up.
This is my code, trying to make a GUI where there's a Text Area and 2 buttons. In which Button2 clears the Text Area, and Button1 checks if you did the math problem it starts with.
The problem was 7x57 which is 237, so I set the String variable, Coolvar to 237 fyi. Just clarifying
The main problem here is I keep getting this error at line 53,
And it's called " ')' expected, "
I tried adding that in but it provided nothing but the error again. I read that it is caused by incorrect bracketing or something but I couldn't find anything wrong.
Please help, here's my sourcecode.
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class TextCheck extends JFrame implements ActionListener
{
JButton Button1 = new JButton("Check Answer");
JButton Button2 = new JButton("Clear Text");
JTextArea Textbox1 = new JTextArea("How much is 5 x 47?");
JPanel bottomPanel = new JPanel();
JPanel holdAll = new JPanel();
String coolvar = "237";
public TextCheck()
{
bottomPanel.setLayout(new FlowLayout());
bottomPanel.add(Button2);
bottomPanel.add(Button1);
holdAll.setLayout(new BorderLayout());
holdAll.add(bottomPanel, BorderLayout.SOUTH);
holdAll.add(Textbox1, BorderLayout.CENTER);
getContentPane().add(holdAll, BorderLayout.CENTER);
Button1.addActionListener(this);
Button2.addActionListener(this);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public static void main(String[] args)
{
TextCheck myApplication = new TextCheck();
myApplication.setLocation(10, 10);
myApplication.setLocation(300, 300);
myApplication.setVisible(true);
JOptionPane.showMessageDialog(frame, "This is a test of a small thing that will test whether you can do basic math");
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == Button2) {
Textbox1.setText();
} if (e.getSource() == Button1) {
if (coolvar.equals(TextArea.getText())) {
TextBox1.setText("Correct!"); }
else
{
TextBox1.setText("Incorrect!");
}
}
}
}
[/size]