我不是新手,也是教授.在Java上.我正在尝试将progressBar添加到我的应用程序中,该应用程序使用isReachable()方法将ping发送到给定的ip范围.我该如何添加?我不知道任务和线程使用情况.我阅读了有关progressBar的java文档,但我无法添加.这是我的代码
final JButton btnScan = new JButton("Scan");
btnScan.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Runtime rt = Runtime.getRuntime();
String lastIpCheck = " ";
String ip = textField.getText();
String lastIp = textField_1.getText();
String parsedOutput= " ";
InetAddress inet;
boolean reachable;
while(!(lastIpCheck.equalsIgnoreCase(lastIp))) {
try {
inet = InetAddress.getByName(ip);
reachable = inet.isReachable(2500);
String output=null;
lastIpCheck = f.nextIpAddress(ip);
if(reachable) {
model.addElement(ip);
}
ip = lastIpCheck;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} …Run Code Online (Sandbox Code Playgroud)