In my logo quiz game I have to take the value written in text Field when the user press ENTER key and compare it with the correct answer.Which listener should I use. I used Action listener but it's not working. I am new to programming.
private JTextField textField=new JTextField("");
textField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
result();
}
});
textField.setBounds(0, 241, 264, 31);
getContentPane().add(textField);
textField.setColumns(10);
private void result(){
answer=textField.getText();
if(answer=="apple"){
JOptionPane.showMessageDialog(this, "right answer");
}
else{
JOptionPane.showMessageDialog(this, "wrong answer");
}
}}