很感谢大家的帮忙,帮我改正其中的错误
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class test9 extends Applet
{
Button button;
public void init()
{
button=new Button("Catch a Exception");
button.addActionListener(new Listener());
add(button);
}
public void testException()
{
int [] arry;
arry=new int[4];
try
{
arry[4]=5;
}
catch(java.lang.ArrayIndexOutOfBoundsException e)
{
System.out.println("Catch a Exception!");
System.out.println("The Exception is ");
e.printStackTrace();
}
}
class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
testException();
}
}
public static void main(String args[])
{
Listener L=new Listener();
L.actionPerformed();
}
}
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class test9 extends Applet
{
Button button;
public void init()
{
button=new Button("Catch a Exception");
button.addActionListener(new Listener());
add(button);
}
public void testException()
{
int [] arry;
arry=new int[4];
try
{
arry[4]=5;
}
catch(java.lang.ArrayIndexOutOfBoundsException e)
{
System.out.println("Catch a Exception!");
System.out.println("The Exception is ");
e.printStackTrace();
}
}
class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
testException();
}
}
public static void main(String args[])
{
Listener L=new Listener();
L.actionPerformed();
}
}
本人是一窍不通啊
不是通过main函数运行的 一般潜入到页面中运行 运行方式由两种 一种是ie访问 一种是appletview...
还有实现ActionListener接口