public class IPFinder extends JFrame
1: //IPFinder.java
2: //Finds the IP address of a domain name.
4: import java.awt.Color;
5: import java.awt.FlowLayout;
6: import java.awt.event.ActionEvent;
7: import java.awt.event.ActionListener;
8: import java.net.InetAddress;
9: import java.net.UnknownHostException;
10: import javax.swing.JFrame;
11: import javax.swing.JButton;
12: import javax.swing.JTextField;
14: public class IPFinder extends JFrame
15: implements ActionListener
16: {
18: private JTextField textOutput, textInput;
19: private JButton displayButton;
21: public static void main(String [] args)
22: {
23: IPFinder app = new IPFinder("IP Finder");
24: app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
25: app.setSize(480, 110);
26: app.setVisible(true);
27: }
29: IPFinder(String s)
30: {
31: super(s);
32: setLayout(new FlowLayout());
34: textInput = new JTextField(42);
35: textOutput = new JTextField(42);
36: displayButton = new JButton("Enter domain name above, then " +
37: "click here to see IP address below ...");
38: displayButton.addActionListener(this);
39: add(textInput);
40: add(displayButton);
41: add(textOutput);
42: getContentPane().setBackground(Color.CYAN);
43: }
45: public void actionPerformed(ActionEvent event)
46: {
47: String host = textInput.getText();
48: try
49: {
50: InetAddress address = InetAddress.getByName(host);
51: textOutput.setText(address.toString());
52: }
53: catch (UnknownHostException e)
54: {
55: textOutput.setText("Could not find " + host);
56: }
57: }
58: }