我不斷收到一個不抽象的消息,並且沒有覆蓋錯誤。我也找不到這個錯誤。我哪裏做錯了?我檢查了大括號是否在正確的位置,而他們似乎是。這是確切的錯誤消息「的addNumbers不是抽象和ActionListener的Java沒有摘要,也沒有覆蓋錯誤
不重寫抽象方法的actionPerformed(ActionEvent的)失蹤的javadoc。」
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class addNumbers extends JFrame implements ActionListener
{
FlowLayout flow = new FlowLayout();
JLabel num1 = new JLabel("First Number: ");
JTextField number1 = new JTextField(10);
JLabel num2 = new JLabel("Second Number: ");
JTextField number2 = new JTextField(10);
JButton sumbutton = new JButton("Sum Numbers");
JButton exitbutton = new JButton("Exit");
JButton reset = new JButton("Reset");
JLabel result = new JLabel("The result is: ");
JLabel add = new JLabel("");
public addNumbers(){
Container con = getContentPane();
con.setLayout(flow);
con.add(num1);
con.add(number1);
con.add(num2);
con.add(number2);
con.add(sumbutton);
con.add(exitbutton);
con.add(reset);
con.add(result);
sumbutton.addActionListener(this);
exitbutton.addActionListener(this);
reset.addActionListener(this);
}//end addNumbers containers
public static void main(String[] args){
addNumbers nframe = new addNumbers();
nframe.setSize(300,300);
nframe.setVisible(true);
nframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
nframe.setTitle("Calculations");
}//end main
public void getAction(ActionEvent e){
Object source = e.getSource();
if(source == sumbutton){
String num1 = number1.getText();
String num2 = number2.getText();
double n1 = Double.parseDouble(num1);
double n2 = Double.parseDouble(num2);
double total = n1+n2;
String result = "" + total;
//convert back to spring to output
add.setText(result);;
}
else if(source == reset){
number1.setText("");
number2.setText("");
add.setText("");
}
else{
System.exit(0);
}
}//end of getAction
}//end addNumbers
[ActionListener可能重複是抽象的,並且不重寫抽象方法actionPerformed - 儘管包含非常方法](http://stackoverflow.com/questions/18813580/actionlistener-is-abstract-and-does-not- override-abstract-method-actionperformed) – 2014-10-01 03:21:43
您可以將此代碼減少到[MCVE](http://stackoverflow.com/help/mcve)嗎? – skrrgwasme 2014-10-01 03:21:58