//pk
//APPLET
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.URL;
import java.net.MalformedURLException;
public class MyUrl extends JApplet implements ActionListener {
JLabel l;
JTextField t;
JButton b;
JPanel p;
public void init() {
p = new JPanel();
l = new JLabel("URL: ");
t = new JTextField("http://www.",20);
b = new JButton("Open");
b.addActionListener(this);
p.add(l);
p.add(t);
p.add(b);
getContentPane().add(p);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b) {
try {
String sUrl = t.getText().trim();
if (sUrl.length() != 0) {
URL url = new URL(sUrl);
getAppletContext().showDocument(url);
} else {
JOptionPane.showMessageDialog(this, "URL cannot be left blank");
}
}
catch (MalformedURLException ex) {
JOptionPane.showMessageDialog(this, "Invalid web address");
}
}
}
}
====
HTML
=====