下面有一个applet代码。我们指定了一个按钮,当按钮被点击时,它应该打开一个新的网站。雅虎网站。applet的代码在
下面public class GotoLinkApplet extends Applet implements ActionListener{
public void init()
{
String link="yahoo";
Button b=new Button(link);
b.addActionListener(this);
add(b);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("1");
Button src= (Button)e.getSource();
String link="http://www."+src.getLabel()+".com";
try{
AppletContext a=getAppletContext();
URL url =new URL(link);
//a.showDocument(url, "_self");
a.showDocument(url, "_blank");
System.out.println("a");
}
catch(MalformedURLException ae)
{
System.out.println(ae.getMessage());
}
}
}
我们在eclipse中执行了上面的代码,但是当我们单击按钮时,没有出现yahoo链接。请求你的帮助。但是指定showdocument的代码运行良好。
对以上任何帮助都是非常感激的。
这应该可以使用Desktop.browse(uri);
你当然要确保桌面是支持的