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不是抽象的,并且不会在ActionListener中覆盖抽象方法actionPerformed(ActionEvent)????
答案 0 :(得分:0)
actionperformed
应该是
actionPerformed
您可以通过添加@Override
注释来轻松测试。