在等待查询完成时合并进度条

时间:2011-04-11 03:09:31

标签: java swing user-interface progress-bar user-experience

我制作了一个程序,用于在本地网络位置显示IP,网络名称和DNS查找。这是获取所有地址的代码:

public void NetworkPing() throws Exception{
    jlist.clear();
    jlist2.clear();
    jlist3.clear();

    InetAddress localhost = InetAddress.getLocalHost();
    byte[] ip = localhost.getAddress();

    for(int i=1;i<254;i++){
        ip[3]=(byte)i;
        InetAddress address = InetAddress.getByAddress(ip);

        if(address.isReachable(1000)){
            jlist.addElement(address); //Machine is turned on and can be ping.
        }else if(!address.getHostAddress().equals(address.getHostName())){
            jlist2.addElement(address); //Machine is known in a dns lookup.
        }else{
            jlist3.addElement(address); //The host address and host name are equal, meaning the host name could not be resolved.
        }
        final DefaultListModel jlist1 = jlist;
        this.jList1.setModel(jlist1);
        final DefaultListModel jlisttwo = jlist2;
        this.jList2.setModel(jlisttwo);
        final DefaultListModel jlistthree = jlist3;
        this.jList3.setModel(jlistthree);
    }
}

此过程需要一些时间才能完成并完全显示到JList。我只想为用户添加一个进度条,以了解完成了多少百分比以及用户如何等待完成所有过程......

我的问题是,如何将进度条与上述代码结合起来?

非常感谢任何帮助。谢谢。

1 个答案:

答案 0 :(得分:3)