-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIP_finder.java
More file actions
63 lines (56 loc) · 1.61 KB
/
IP_finder.java
File metadata and controls
63 lines (56 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package swings;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class IP_finder {
JFrame frame;
JPanel mainpanel;
JLabel l;
JLabel exc;
JTextField field;
JButton button;
public static void main(String[] args) {
IP_finder p = new IP_finder();
p.go();
}
private void go() {
// TODO Auto-generated method stub
frame = new JFrame("IP Finder");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainpanel = new JPanel();
field = new JTextField(20);
button = new JButton("Find IP");
button.addActionListener(new ButtonActionListener());
JLabel label = new JLabel("Enter website:");
l = new JLabel();
exc = new JLabel();
mainpanel.add(label);
mainpanel.add(field);
mainpanel.add(button);
mainpanel.add(l);
mainpanel.add(exc);
frame.getContentPane().add(mainpanel);
frame.setSize(500, 300);
frame.setVisible(true);
}
class ButtonActionListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
try{
String host=field.getText();
String ip=java.net.InetAddress.getByName(host).getHostAddress();
l.setText("IP of "+host+" is: "+ip+".");
field.setText("");
exc.setText("");
}catch(Exception ex){
exc.setText("Not a correct website name");
}
}
}
}