home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 2.0 KB | 89 lines |
-
- import java.awt.*;
- import java.awt.event.*;
- import java.net.*;
- import java.applet.*;
-
- /*
- * Lookup application class
- */
- public class Lookup extends Applet implements ActionListener {
-
- /*
- * text field for host name
- */
- TextField nameField;
-
- Button btnLookup;
-
- /*
- * text area for displaying Internet addresses
- */
- TextArea addrArea;
-
- /*
- * instance of InetAddress needed for name-to-address
- * translation
- */
- InetAddress inetAddr;
-
- /*
- * insertion point in the Internet address
- * text area
- */
- int insertIndex;
-
- /*
- * constructor creates user interface
- */
- public void init () {
-
- super.init();
-
- setLayout (new BorderLayout ());
-
- Panel editPanel = new Panel ();
- editPanel.setLayout (new BorderLayout ());
- editPanel.add ("North", new Label ("Host name"));
- nameField = new TextField ("", 32);
- btnLookup = new Button("Lookup");
- editPanel.add ("Center", nameField);
- editPanel.add ("South", btnLookup);
-
- add ("North", editPanel);
-
- Panel areaPanel = new Panel ();
- areaPanel.setLayout (new BorderLayout ());
- addrArea = new TextArea ("", 24, 32);
- addrArea.setEditable (false);
- areaPanel.add ("North", new Label ("Internet address"));
- areaPanel.add ("Center", addrArea);
-
- add ("Center", areaPanel);
- btnLookup.addActionListener(this);
-
- insertIndex = 0;
-
- setSize (300, 200);
- }
-
- public void actionPerformed(ActionEvent ev)
- {
- String name = nameField.getText ();
- try
- {
- inetAddr = InetAddress.getByName (name);
- String str = inetAddr.toString () + "\n";
- addrArea.insert (str, insertIndex);
- insertIndex += str.length ();
- } catch (UnknownHostException ex)
- {
- String str = name + "/ No such host\n";
- addrArea.insert (str, insertIndex);
- insertIndex += str.length ();
- }
- }
-
- } // end of Applet
-
-