HostNameField.java



package xmlshare;

import java.awt.event.*;
import javax.swing.*;

/** Input Host Name */
public class HostNameField extends JPanel {

  /** the JTextField object */
    public JTextField field;

  /** parent */
    ActionListener parent;

  /** constructor */
    public HostNameField( ActionListener parent ) {

        this.parent = parent;

        JLabel label = new JLabel( "Host:" );
        add(label);
        field = new JTextField( "", 16 );
        add(field);
        JButton button = new JButton( "Connect:" );
        add(button);

        MyAdapter adapter = new MyAdapter();
        field.addActionListener( adapter );
        button.addActionListener( adapter );
    }

  /** return host name */
    public String getHostName() {

        return field.getText();
    }

  /** inner class for event handling */
    class MyAdapter implements ActionListener {

         public void actionPerformed( ActionEvent evt ) {

             parent.actionPerformed( evt );
         }
    }
}