import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class UrlTest extends Frame implements ActionListener, WindowListener {
    private TextField messageh = new TextField(40);
    private TextField messagef = new TextField(40);
    private TextField inp = new TextField(40);
    private Label lab = new Label("Put full URL into first textfield");
    
    public static void main(String[] args) {
        UrlTest applic = new UrlTest();
        applic.setSize(400,200);
        applic.setVisible(true); 
    } // main
    
    public UrlTest() {
        super("UrlTest");     
        setLayout(new FlowLayout());
        add(lab);
        add(inp);
        inp.addActionListener(this);
        add(messageh);add(messagef);
        this.addWindowListener(this);       
    } // constructor
        
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == inp) {
            String s = inp.getText();
            try {
                URL cpl = new URL(s);
                String shost = cpl.getHost();
                String sfile = cpl.getFile();
                messageh.setText("host is: " + shost);
                messagef.setText("file is: " + sfile);
            }
            catch (Exception ex) {
                messageh.setText("wrong URL");
            }               
        }
    } // actionPerformed
        
    // End the session by closing the window
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    } // windowClosing

    public void windowIconified(WindowEvent e) {}
    public void windowOpened(WindowEvent e) {}
    public void windowClosed(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}
    public void windowActivated(WindowEvent e) {}
    public void windowDeactivated(WindowEvent e) {}
} // UrlTest