import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.Applet;
class HomeButton extends Button{
String name;
URL home;
HomeButton(String name,String site){
setLabel(name);
try{
home=new URL(site);
}catch(MalformedURLException e){}
}
}
public class URLforAddress extends Applet implements ActionListener{
HomeButton loveHome=new HomeButton("中国爱心网","http://www.chainloveweb.com");
HomeButton javaHome=new HomeButton("java","http://java.sun.com");
public void init(){
add(loveHome);
add(javaHome);
loveHome.addActionListener(this);
javaHome.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
HomeButton btn=(HomeButton)e.getSource();
getAppletContext().showDocument(btn.home);
}
}
网页里运行是小程序载入失败