当前位置: 首页 > 知识库问答 >
问题:

AListener不是抽象的,并且不会覆盖ActionListener中的抽象方法actionPerformed(ActionEvent)

阎功
2023-03-14
public class AListener implements ActionListener {
    private JTextField tf1, tf2, tf3;

    public AListener (JTextField tf1, JTextField tf2, JTextField tf3){
        this.tf1= tf1;
        this.tf2=tf2;
        this.tf3=tf3;
    }

    public void actionperformed(ActionEvent e){
        float number1= Float.parseFloat(tf1.getText());
        float number2= Float.parseFloat(tf2.getText());
        if(e.getActionCommand().equals("ADD")){
            tf3.setText(number1+number2+"");
        }
        else if(e.getActionCommand().equals("SUBTRACT")){
        tf3.setActionCommand(number1-number2+"");}
        else if(e.getActionCommand().equals("MULTIPLY")){
        tf3.setActionCommand(number1*number2+"");}
        else if(e.getActionCommand().equals("Divide")){
        tf3.setActionCommand(number1/number2+"");}          
        }         
    }

//AListener不是抽象的,也不会覆盖抽象方法actionPerform(ActionEvener)中的ActionListener????

共有1个答案

穆乐逸
2023-03-14
actionperformed

应该是

actionPerformed

您可以通过添加@Override注释轻松测试这一点。

 类似资料: