当前位置: 技术问答>java相关
简单的问题马上给分!
来源: 互联网 发布时间:2015-10-09
本文导语: package test; import java.util.*; import java.awt.*; import java.awt.event.*; import java.applet.*; public class Add extends Applet implements ActionListener { TextField textField1 = new TextField(6); TextField textField2 = new TextField(6); Button button1 = n...
package test;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Add extends Applet implements ActionListener
{
TextField textField1 = new TextField(6);
TextField textField2 = new TextField(6);
Button button1 = new Button("相加");
Label label1 = new Label(" ");
Label label2 = new Label("=");
public void init()
{
add(textField1);
add(textField2);
add(label1);
add(label2);
add(button1);
button1.addActionListener(this);
resize(300,400);
}
public void ActionPerformed(ActionEvent e)
{
int x = Integer.parseInt(textField1.getText())+Integer.parseInt(textField2.getText());
label1.setText(Integer.toString(x));
}
}
错误提示:C:resin-2.1.4webappscimsclassestestAdd.java:6: test.Add should be declared abstract; it does not define actionPerformed(java.awt.event.ActionEvent) in test.Add
public class Add extends Applet implements ActionListener
^
1 error
把public换为abstract就ok了!这是为什么?
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Add extends Applet implements ActionListener
{
TextField textField1 = new TextField(6);
TextField textField2 = new TextField(6);
Button button1 = new Button("相加");
Label label1 = new Label(" ");
Label label2 = new Label("=");
public void init()
{
add(textField1);
add(textField2);
add(label1);
add(label2);
add(button1);
button1.addActionListener(this);
resize(300,400);
}
public void ActionPerformed(ActionEvent e)
{
int x = Integer.parseInt(textField1.getText())+Integer.parseInt(textField2.getText());
label1.setText(Integer.toString(x));
}
}
错误提示:C:resin-2.1.4webappscimsclassestestAdd.java:6: test.Add should be declared abstract; it does not define actionPerformed(java.awt.event.ActionEvent) in test.Add
public class Add extends Applet implements ActionListener
^
1 error
把public换为abstract就ok了!这是为什么?
|
public void ActionPerformed(ActionEvent e)
改为actionPerformer(ActionEvent e)
改为actionPerformer(ActionEvent e)