当前位置: 技术问答>java相关
新手请大家帮忙100分!!!!急急!!!
来源: 互联网 发布时间:2015-07-17
本文导语: 小弟刚学是java,不知如何将java程序改写为javabean请大家帮忙....重谢!!! 其中有两个方法:getMyIP() 为取用户的IP,getServerIP()为取服务器的IP. 原代码为: import java.net.*; public class NetTool{ InetAddress myIPaddress=null; InetAddress myServ...
小弟刚学是java,不知如何将java程序改写为javabean请大家帮忙....重谢!!!
其中有两个方法:getMyIP() 为取用户的IP,getServerIP()为取服务器的IP.
原代码为:
import java.net.*;
public class NetTool{
InetAddress myIPaddress=null;
InetAddress myServer=null;
public static void main( String args[]){
NetTool mytool;
mytool=new NetTool();
System.out.println("Your host IP is: "
+ mytool.getMyIP());
System.out.println("The Server IP is :"
+mytool.getServerIP());
}
//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try { myIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (myIPaddress);
}
//取得 www.abc.com 的IP地址
public InetAddress getServerIP(){
try {myServer=InetAddress.getByName(
"www.abc.com");}
catch (UnknownHostException e) {}
return (myServer);
}
}
其中有两个方法:getMyIP() 为取用户的IP,getServerIP()为取服务器的IP.
原代码为:
import java.net.*;
public class NetTool{
InetAddress myIPaddress=null;
InetAddress myServer=null;
public static void main( String args[]){
NetTool mytool;
mytool=new NetTool();
System.out.println("Your host IP is: "
+ mytool.getMyIP());
System.out.println("The Server IP is :"
+mytool.getServerIP());
}
//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try { myIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (myIPaddress);
}
//取得 www.abc.com 的IP地址
public InetAddress getServerIP(){
try {myServer=InetAddress.getByName(
"www.abc.com");}
catch (UnknownHostException e) {}
return (myServer);
}
}
|
这种情况我以前有过,这是一种比较低级的错误,请你仔细查验一下你在public class NetTool{一句中的名称和你定义的名称是否一样就可以了!
|
import java.net.*;
public class NetTool{
InetAddress myIPaddress=null;
InetAddress myServer=null;
//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try { myIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (myIPaddress);
}
//取得 www.abc.com 的IP地址
public InetAddress getServerIP(){
try {myServer=InetAddress.getByName(
"www.abc.com");}
catch (UnknownHostException e) {}
return (myServer);
}
}
public class NetTool{
InetAddress myIPaddress=null;
InetAddress myServer=null;
//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try { myIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (myIPaddress);
}
//取得 www.abc.com 的IP地址
public InetAddress getServerIP(){
try {myServer=InetAddress.getByName(
"www.abc.com");}
catch (UnknownHostException e) {}
return (myServer);
}
}
|
JAVABEANS应该就是一个类,我在 Jcreator 编辑器里编译通过了,jdk1.3