把这个JAVA文件编译成CLASS文件后
源代码在线查看: example2.java
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class Example2 extends Applet implements ActionListener{
Button button;
URL url;
TextField text;
public void init(){
text=new TextField("http://",20);
button=new Button("ok");
add(new Label("Enter the net address:"));add(text);add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==button){
try{
url=new URL(text.getText().trim());
}
catch(MalformedURLException g){
text.setText("Awrong address!");
}
getAppletContext().showDocument(url);
}
}
}