public class IPFinder extends Frame
1: // IPFinder.java
2: // Finds the IP address of a domain name.
4: import java.awt.*;
5: import java.net.*;
6: import java.io.*;
7: import java.awt.event.*;
9: public class IPFinder extends Frame
10: implements ActionListener
11: {
13: private TextField txtOutput, txtInput;
14: private Button btnDisplay;
15: private Button exit;
17: public static void main(String [] args)
18: {
19: IPFinder m = new IPFinder();
20: m.makeGUI();
21: m.setSize(500, 100);
22: m.setVisible(true);
23: }
25: public void makeGUI()
26: {
27: setLayout(new FlowLayout());
29: txtInput = new TextField(50);
30: txtOutput = new TextField(50);
31: btnDisplay = new Button("Display");
32: btnDisplay.addActionListener(this);
33: add(txtInput);
34: add(btnDisplay);
35: add(txtOutput);
37: exit = new Button("Exit");
38: add(exit);
39: exit.addActionListener(this);
40: }
42: public void actionPerformed(ActionEvent event)
43: {
44: if (event.getSource() == exit) System.exit(0);
46: String host = txtInput.getText();
47: try
48: {
49: InetAddress address = InetAddress.getByName(host);
50: txtOutput.setText(address.toString());
51: }
52: catch (UnknownHostException e)
53: {
54: txtOutput.setText("Could not find " + host);
55: }
56: }
57: }