登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

love3400wind的blog

like

 
 
 

日志

 
 
 
 

java 输入域名查询相应ip地址  

2011-06-24 11:40:29|  分类: IT |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

import java.net.*;
import java.awt.*;
import java.awt.event.*;

public class CZIP extends Frame implements ActionListener {
 TextField text1, text2, text3;
 Label lab1, lab2, lab3;
 Button but1, but2;
 URL add;
 InetAddress ip;

 CZIP() {
  super("IP地址查询窗口");
  setSize(400, 150);
  setLayout(null);
  text1 = new TextField(30);
  text1.setBounds(160, 36, 220, 20);
  text2 = new TextField(30);
  text2.setBounds(160, 66, 220, 20);
  text3 = new TextField(16);
  text3.setBounds(160, 96, 100, 20);
  lab1 = new Label("所查URL(例如:http://www.baidu.com):");
  lab1.setBounds(10, 30, 120, 30);
  lab2 = new Label("主机域名(例如:www.baidu.com):");
  lab2.setBounds(10, 60, 120, 30);
  lab3 = new Label("主机IP地址");
  lab3.setBounds(10, 90, 120, 30);
  but1 = new Button("查询");
  but1.setBounds(276, 96, 50, 20);
  but2 = new Button("退出");
  but2.setBounds(330, 96, 50, 20);
  add(lab1);
  add(text1);
  add(lab2);
  add(text2);
  add(lab3);
  add(text3);
  add(but1);
  add(but2);
  text1.addActionListener(this);
  but1.addActionListener(this);
  but2.addActionListener(this);
  setVisible(true);
  validate();

 }

 public void actionPerformed(ActionEvent e) {

  try {
   add = new URL(text1.getText().trim());
   ip = InetAddress.getByName(add.getHost());
  } catch (MalformedURLException murle) {
   System.out.println(murle);
  } catch (UnknownHostException uh) {

  }
  if (e.getSource() == text1) {
   text2.setText("");
   text3.setText("");
  }
  if (e.getSource() == but1) {
   if (text1.getText() != "") {
    text2.setText(ip.getHostName());
    text3.setText(ip.getHostAddress());
   }
  }
  if (e.getSource() == but2)
   System.exit(0);
 }

 public static void main(String args[]) {
  new CZIP();

 }
}

  评论这张
 
阅读(1217)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018