当前位置: 代码迷 >> Java相关 >> [求助]本机ip问题
  详细解决方案

[求助]本机ip问题

热度:290   发布时间:2006-06-19 09:42:41.0
[求助]本机ip问题

import javax.swing.JFrame;
import java.net.*;
import java.awt.*;
public class ip extends JFrame{
InetAddress inet;
ip(){
setTitle("本机IP测试");
setSize(300,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try{
inet=InetAddress.getLocalHost();
}catch(UnKnownHostException e){};
setVisible(true);
}
public void paint(Graphics g){
g.drawString("本机IP地址为:"+inet.getHostAddress(),30,50);

}
public static void main(String[] agrs){
ip ip=new ip();
}
}

搜索更多相关的解决方案: void  IP地址  public  import  

----------------解决方案--------------------------------------------------------
运行不起来啊
----------------解决方案--------------------------------------------------------
catch(UnKnownHostException e){};
你错了,应该改为小写的

----------------解决方案--------------------------------------------------------
以下是引用kuangwo1在2006-6-19 9:42:41的发言:

import javax.swing.JFrame;
import java.net.*;
import java.awt.*;
public class ip extends JFrame{
InetAddress inet;
ip(){
setTitle("本机IP测试");
setSize(300,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try{
inet=InetAddress.getLocalHost();
}catch(UnKnownHostException e){};//k不是应该小写吗
setVisible(true);
}
public void paint(Graphics g){
g.drawString("本机IP地址为:"+inet.getHostAddress(),30,50);

}
public static void main(String[] agrs){
ip ip=new ip();
}
}


----------------解决方案--------------------------------------------------------
运行成功。谢谢。。。 解解热
----------------解决方案--------------------------------------------------------

  相关解决方案