java textfield赋值_Java中怎么把运行结果显示到textfield中
兩種辦法:
1) 在原有方法里加設(shè)置到textfield的命令
public static void ipaddress()
{
try{
InetAddress inet = InetAddress.getLocalHost();
System.out.println(inet.getHostAddress());
text1.setText(inet.getHostAddress());//new added
}
catch(UnknownHostException e){
System.err.println("UnknownHostException" + e.getMessage());
}
}
2) 方法改返回值.
public static String ipaddress()
{
String ret = null;
try{
InetAddress inet = InetAddress.getLocalHost();
ret=inet.getHostAddress();
System.out.println(ret);
}
catch(UnknownHostException e){
System.err.println("UnknownHostException" + e.getMessage());
}
return ret;
}
然后在調(diào)用此方法的后面,加
text1.setText(inet.getHostAddress());
取消
評論
總結(jié)
以上是生活随笔為你收集整理的java textfield赋值_Java中怎么把运行结果显示到textfield中的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos命令行安装mysql_Cen
- 下一篇: php用asp文件js,asp下用fso