刚刚想到了个方法,拿出来和大家共享
void openLink(String link) {
AppletContext appletCon=getAppletContext();
try {
appletCon.showDocument(new URL(link),"_blank");
}catch(MalformedURLException e) {System.out.println(link+e);}
}
void openLink(String link) {
AppletContext appletCon=getAppletContext();
try {
appletCon.showDocument(new URL(link),"_blank");
}catch(MalformedURLException e) {System.out.println(link+e);}
}
type a new URL in a textfield, and press a button to go to that page.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;public class GotoURLButton extends Applet implements
ActionListener {
Button b;
TextField t;
public void init() {
t = new TextField(20);
add(t);
b = new Button("Go to this URL");
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == b) {
try {
getAppletContext().showDocument(new URL(t.getText()));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}