AppletIntegerl cannot be cast to java.awt.event.ActionListener
importjava.awt.*;importjava.awt.event.*;importjava.applet.*;publicclassAppletIntegerl...
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AppletIntegerl extends Applet implements
ActionListerner{
Label inputLB;
TextField input;
int ing;
Integer outIng;
String str1,str2,str3;
public void init(){
inputLB=new Label("请输入一个数字字符串:");
input = new TextField(5);
add (inputLB);
add (input);
input.addActionListener(this);
}
public void paint(Graphics g){
g.drawString ("二进制表示:"+str1,100,100);
g.drawString("十六进制表示:"+str2,100,150);
g.drawString("八进制表示:"+str3, 100, 200);
}
public void actionPerformed(ActionEvent e){
ing=Integer.valueOf(input.getText()).intValue();
outIng=new Integer(ing);
str1=outIng.toBinaryString(ing);
str2=outIng.toHexString(ing);
str3=outIng.toOctalString(ing);
repaint();
}
}
上面为程序
下面为报错
java.lang.ClassCastException: AppletIntegerl cannot be cast to java.awt.event.ActionListener
at AppletIntegerl.init(AppletIntegerl.java:17)
at sun.applet.AppletPanel.run(AppletPanel.java:424)
at java.lang.Thread.run(Thread.java:619)
在编写的代码中有错误,不知道为什么?
public void init(){
inputLB=new Label("请输入一个数字字符串:");
input = new TextField(5);
add (inputLB);
add (input);
input.addActionListener(this);//这句有问题,在MyEclipse里面报错
} 展开
import java.awt.event.*;
import java.applet.*;
public class AppletIntegerl extends Applet implements
ActionListerner{
Label inputLB;
TextField input;
int ing;
Integer outIng;
String str1,str2,str3;
public void init(){
inputLB=new Label("请输入一个数字字符串:");
input = new TextField(5);
add (inputLB);
add (input);
input.addActionListener(this);
}
public void paint(Graphics g){
g.drawString ("二进制表示:"+str1,100,100);
g.drawString("十六进制表示:"+str2,100,150);
g.drawString("八进制表示:"+str3, 100, 200);
}
public void actionPerformed(ActionEvent e){
ing=Integer.valueOf(input.getText()).intValue();
outIng=new Integer(ing);
str1=outIng.toBinaryString(ing);
str2=outIng.toHexString(ing);
str3=outIng.toOctalString(ing);
repaint();
}
}
上面为程序
下面为报错
java.lang.ClassCastException: AppletIntegerl cannot be cast to java.awt.event.ActionListener
at AppletIntegerl.init(AppletIntegerl.java:17)
at sun.applet.AppletPanel.run(AppletPanel.java:424)
at java.lang.Thread.run(Thread.java:619)
在编写的代码中有错误,不知道为什么?
public void init(){
inputLB=new Label("请输入一个数字字符串:");
input = new TextField(5);
add (inputLB);
add (input);
input.addActionListener(this);//这句有问题,在MyEclipse里面报错
} 展开
1个回答
展开全部
正确代码如下:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AppletIntegerl extends Applet implements ActionListener{
Label inputLB;
TextField input;
int ing;
Integer outIng;
String str1,str2,str3;
public void init(){
inputLB=new Label("请输入一个数字字符串:");
input = new TextField(5);
add (inputLB);
add (input);
input.addActionListener(this);
}
public void paint(Graphics g){
g.drawString ("二进制表示:"+str1,100,100);
g.drawString("十六进制表示:"+str2,100,150);
g.drawString("八进制表示:"+str3, 100, 200);
}
public void actionPerformed(ActionEvent e){
ing=Integer.valueOf(input.getText()).intValue();
outIng=new Integer(ing);
str1=outIng.toBinaryString(ing);
str2=outIng.toHexString(ing);
str3=outIng.toOctalString(ing);
repaint();
}
}
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AppletIntegerl extends Applet implements ActionListener{
Label inputLB;
TextField input;
int ing;
Integer outIng;
String str1,str2,str3;
public void init(){
inputLB=new Label("请输入一个数字字符串:");
input = new TextField(5);
add (inputLB);
add (input);
input.addActionListener(this);
}
public void paint(Graphics g){
g.drawString ("二进制表示:"+str1,100,100);
g.drawString("十六进制表示:"+str2,100,150);
g.drawString("八进制表示:"+str3, 100, 200);
}
public void actionPerformed(ActionEvent e){
ing=Integer.valueOf(input.getText()).intValue();
outIng=new Integer(ing);
str1=outIng.toBinaryString(ing);
str2=outIng.toHexString(ing);
str3=outIng.toOctalString(ing);
repaint();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询