编译器显示的错误是: -
" Slot_Machine不是抽象的,并且不会覆盖java.awt.event.ActionListener中的抽象方法actionPerformed(java.awt.event.ActionEvent)。"
该计划是: -
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Slot_Machine extends Applet implements ActionListener
{
public void init()
{
Button B1 = new Button("Start");
B1.addActionListener(this);
add(B1);
}
public void paint(Graphics g)
{
int mm = 5000;
int x1[] = {245,210,210,245,315,350,350,315};
int y1[] = {175,315,385,525,525,385,315,175};
int n1 = x1.length;
int x2[] = {455,420,420,455,525,560,560,525};
int x3[] = {665,630,630,665,735,770,770,735};
g.setColor(Color.red);
g.fillPolygon(x1,y1,n1);
g.fillPolygon(x2,y1,n1);
g.fillPolygon(x3,y1,n1);
int x4[] = {280,245,315};
int y4[] = {210,280,280};
int n4 = x4.length;
int x5[] = {490,455,525};
int x6[] = {700,665,735};
int x7[] = {245,280,315};
int y7[] = {420,490,420};
int n7 = x7.length;
int x8[] = {455,490,525};
int x9[] = {665,700,735};
g.setColor(Color.green);
g.fillPolygon(x4,y4,n4);
g.fillPolygon(x5,y4,n4);
g.fillPolygon(x6,y4,n4);
g.fillPolygon(x7,y7,n7);
g.fillPolygon(x8,y7,n7);
g.fillPolygon(x9,y7,n7);
g.setColor(Color.yellow);
g.fillRect(245,315,70,70);
g.fillRect(455,315,70,70);
g.fillRect(665,315,70,70);
Font F1 = new Font ("courier new", Font.BOLD,20);
g.setFont(F1);
Button B1 = new Button ("Start");
}
}
答案 0 :(得分:1)
您已将该类标记为实现ActionListener接口,但您根本没有实际实现它。
您必须在班级中使用此方法
public void actionPerformed(ActionEvent e) {
}
参考:http://www.tutorialspoint.com/awt/awt_action_listener.htm
答案 1 :(得分:0)
如果它应该是ActionListener
,那么您需要实现ActionListener
接口。否则,不要说它是ActionListener
执行:
void actionPerformed(java.awt.event.ActionEvent) {
// stuff
}
或
public class Slot_Machine extends Applet