Reputation: 67
I'm trying to build a quiz program.
I decided that users enter their answers(numbers) into a JTextArea and the result will be shown on another JTextArea after a button click however I'm having troubles.
Here is partial of my code.
JButton btnNewButton = new JButton("Submit!");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(textArea_3.equals("1"))
{
textArea_1.setText("Correct!");
}
}
});
Upvotes: 1
Views: 703
Reputation: 589
if(textArea_3.equals("1"))
should be
if(textArea_3.getText().equals("1"))
Upvotes: 0
Reputation: 69005
I think you mean -
if(textArea_3.getText().equals("1"))
{
textArea_1.setText("Correct!");
//your code
}
and not
textArea_3.equals("1")
You cannot compare JTextArea instance with a String instance. You will always get false.
Upvotes: 2