我的java程序运行不了,不知道什么地方出了错误。
程序代码:import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class Mycanvas extends Canvas
{int x,y;
Mycanvas(int a,int b)
{x=a;y=b;
setSize(100,160);
}
public void paint(Graphics g)
{g.setColor(Color.red);
g.fillOval(50,50,4*x,4*y);
g.drawString("我是第 "+x,10,150);
}
}
public class e123 extends Applet implements ActionListener
{
CardLayout mycard;
Button button1,button2,button3;
Mycanvas mycanvas[];
Panel p;
/** Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init() {
setLayout(new BorderLayout());
mycard=new CardLayout();
p=new Panel();
p.setLayout(mycard);
button1=new Button("first");
button2=new Button("next");
button3=new Button("last one");
mycanvas=new Mycanvas[21];
for(int i=1;i<=20;i++)
{mycanvas[i]=new Mycanvas(i,i);
p.add("i am"+i,mycanvas[i]);
}
button1.addActionListener(this);
button2.addActionListener(this); // TODO start asynchronous download of heavy resources
button3.addActionListener(this);
Panel p2=new Panel();
p2.add(button1);p2.add(button2);p2.add(button3);
add(p,BorderLayout.CENTER);add(p2,BorderLayout.SOUTH);
}
public void actionPerformed(ActiveEvent e)
{if(e.getSource()==button1)
{mycard.first(p);
}
else if(e.getSource()==button2)
{mycard.next(p);
}
else if(e.getSource()==button3)
{mycard.last(p);
}
}
}源代码:
但编译时出现错误:
e123.java:25: e123 不是抽象的,并且未覆盖 java.awt.event.ActionListener 中的抽象
方法 actionPerformed(java.awt.event.ActionEvent)
public class e123 extends java.applet.Applet implements ActionListener
^
e123.java:57: 找不到符号
符号: 方法 getSource()
位置: 接口 java.awt.ActiveEvent
{if(e.getSource()==button1)
^
e123.java:60: 找不到符号
符号: 方法 getSource()
位置: 接口 java.awt.ActiveEvent
else if(e.getSource()==button2)
^
e123.java:63: 找不到符号
符号: 方法 getSource()
位置: 接口 java.awt.ActiveEvent
else if(e.getSource()==button3)
^
4 错误