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()));//打开Html
==============
URL verisign = new URL(t.getText());//打开文件data
URLConnection urlc = verisign.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(verisign.openStream()));
......
==============
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
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()));//打开Html
==============
URL verisign = new URL(t.getText());//打开文件data
URLConnection urlc = verisign.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(verisign.openStream()));
......
==============
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
我试了下,怎样才能在新开窗口中打开想要的页面呢,再谢!
只是 t.getText() 不能是c:\yourdir\yourfile.html 而应该 如:ttp://www.yourname.com/dddddd.html