当前位置: 技术问答>java相关
为什么总是报错。。。向高手请教一个很菜的问题。解决后就给分。
来源: 互联网 发布时间:2015-01-09
本文导语: 下面一段代码为什么我一运行就会报错呢我怎也找不到出错的地方: 注释的地方就是报错的信息: package untitled1; import java.awt.*; import java.applet.*; import java.awt.event.*; public class Applet1 extends Applet implements ActionListe...
下面一段代码为什么我一运行就会报错呢我怎也找不到出错的地方:
注释的地方就是报错的信息:
package untitled1;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Applet1 extends Applet implements ActionListener
{
public TextField passwdField;
public TextField userField;
public TextArea info;
public String user = "public";
public String passwd = "123456";
private String displayStr;
Button button1 = new Button("登录");
public void init(){
setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
info = new TextArea("请输入用户名和密码:n 用户名:publicn 密码:123456n ",6,60);
add(info);
Label userLabel = new Label("用户名");
add(userLabel);
userField = new TextField(10);
Label passwdLabel = new Label("密码");
add(passwdLabel);
passwdField = new TextField(10);
passwdField.setEchoChar('*');
add(passwdField);
add(button1);
button1.addActionListener(this);
}
public void paint(Graphics g){
g.drawString(displayStr,80,180);
}
public void actonPerformed(ActionEvent ev){
String label = ev.getActionCommand();
if(label.equals("登录"))
{
String userIn = userField.getText();
String passwdIn = passwdField.getText();
if(user.equals(userIn)&&passwd.equals(passwdIn))
displayStr="成功登录";
else
displayStr="用户名或密码不正确";
}
repaint();
}
}
// "Applet1.java": Error #: 454 : class untitled1.Applet1 should be declared abstract; it does not define method actionPerformed(java.awt.event.ActionEvent) in interface java.awt.event.ActionListener at line 6, column 8
注释的地方就是报错的信息:
package untitled1;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Applet1 extends Applet implements ActionListener
{
public TextField passwdField;
public TextField userField;
public TextArea info;
public String user = "public";
public String passwd = "123456";
private String displayStr;
Button button1 = new Button("登录");
public void init(){
setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
info = new TextArea("请输入用户名和密码:n 用户名:publicn 密码:123456n ",6,60);
add(info);
Label userLabel = new Label("用户名");
add(userLabel);
userField = new TextField(10);
Label passwdLabel = new Label("密码");
add(passwdLabel);
passwdField = new TextField(10);
passwdField.setEchoChar('*');
add(passwdField);
add(button1);
button1.addActionListener(this);
}
public void paint(Graphics g){
g.drawString(displayStr,80,180);
}
public void actonPerformed(ActionEvent ev){
String label = ev.getActionCommand();
if(label.equals("登录"))
{
String userIn = userField.getText();
String passwdIn = passwdField.getText();
if(user.equals(userIn)&&passwd.equals(passwdIn))
displayStr="成功登录";
else
displayStr="用户名或密码不正确";
}
repaint();
}
}
// "Applet1.java": Error #: 454 : class untitled1.Applet1 should be declared abstract; it does not define method actionPerformed(java.awt.event.ActionEvent) in interface java.awt.event.ActionListener at line 6, column 8
|
public void actonPerformed(ActionEvent ev){
.....
}
写错啦!!!!
应该是
public void actionPerformed(ActionEvent ev){
.....
}
呵呵!
.....
}
写错啦!!!!
应该是
public void actionPerformed(ActionEvent ev){
.....
}
呵呵!