Java:Actionlistener标识符预期错误

Java:Actionlistener标识符预期错误,java,overriding,actionlistener,Java,Overriding,Actionlistener,我试图创建一个方法,通过使用ActionListener从用户的文本字段中获取输入。然而,当我编译时,我总是会遇到以下错误: Quiz.java:36: error: <identifier> expected tfInput.addActionListener(new a ActionListener() { 我不明白是什么原因造成了这种情况。试着这样做,也许: frame.setVisible(true); tfInput.addActionListener(ne

我试图创建一个方法,通过使用ActionListener从用户的文本字段中获取输入。然而,当我编译时,我总是会遇到以下错误:

Quiz.java:36: error: <identifier> expected
  tfInput.addActionListener(new  a ActionListener() {
我不明白是什么原因造成了这种情况。

试着这样做,也许:

  frame.setVisible(true);
  tfInput.addActionListener(new  ActionListener() {

       @Override
       public void actionPerformed(ActionEvent e) {        
         String inLand = tfInput.getText(); 
       }       
    });   
  }
 }

您在
tfInput.addActionListener(new ActionListener()
中缺少一个
,看起来这段代码不是上述方法的一部分?我在哪里缺少一个
  frame.setVisible(true);
  tfInput.addActionListener(new  ActionListener() {

       @Override
       public void actionPerformed(ActionEvent e) {        
         String inLand = tfInput.getText(); 
       }       
    });   
  }
 }