Mia_tech
April 18th, 2009, 07:27 AM
guys, I'm trying to get working a progress bar for my "IP Scanner" app (netbeans project), the progress bar I set it to go off when I press the "start" button and the frame shows up, but not the progress bar itself <attached file> the complete progress bar shows up once the task is completed "that's no fun"... also I inserted the "progressBar1.setValue(i);" in the for(loop) that scans for IP's so it gets the update to the bar, but that's not working either... guys what am I missing here?.... HELP!
progress bar method
public JProgressBar progressBar1;
public JFrame frame;
private void buttonStartIPscanActionPerformed(java.awt.event.Ac tionEvent evt) {
/**
* progress bar displaying ip scan
*/
frame = new JFrame("IP Scanner");
Container content = frame.getContentPane();
JButton cancel = new JButton("Cancel");
cancel.setSize(50, 25);
content.add(cancel);
progressBar1 = new JProgressBar();
progressBar1.setMinimum(0);
progressBar1.setMaximum(block.size());
progressBar1.setStringPainted(true);
Border border = BorderFactory.createTitledBorder("Scanning...");
progressBar1.setBorder(border);
content.add(progressBar1, BorderLayout.NORTH);
frame.setSize(300, 100);
frame.setVisible(true);
}
IP Scan method
IPrange netRange = new IPrange();
ArrayList<String> block = netRange.getRange();
/**
* performing ip scan
*/
@Action
public void StartIPscan()
{
String ipFrom = txtboxIPfrom.getText();
String ipTo = txtboxIPto.getText();
netRange.setFromip(ipFrom);
netRange.setToip(ipTo);
netRange.StrToIP();
netRange.calcNetwork();
/**
* ping sweep network
*/
boolean ping = false;
String ipadd = "";
ipadd = "Scanning network "+"\""+block.get(0)+"\""+"...."+"\n";
txtareaIPscan.setText(ipadd);
for(int i = 0; i < block.size(); i++)
{
try
{
int timeout = 1500;
InetAddress address = InetAddress.getByName(block.get(i));
ping = address.isReachable(timeout);
progressBar1.setValue(i);//updating progress bar
if(ping == true)
{
ipadd = block.get(i)+" is alive!"+"\n";
txtareaIPscan.append(ipadd);
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}
progress bar method
public JProgressBar progressBar1;
public JFrame frame;
private void buttonStartIPscanActionPerformed(java.awt.event.Ac tionEvent evt) {
/**
* progress bar displaying ip scan
*/
frame = new JFrame("IP Scanner");
Container content = frame.getContentPane();
JButton cancel = new JButton("Cancel");
cancel.setSize(50, 25);
content.add(cancel);
progressBar1 = new JProgressBar();
progressBar1.setMinimum(0);
progressBar1.setMaximum(block.size());
progressBar1.setStringPainted(true);
Border border = BorderFactory.createTitledBorder("Scanning...");
progressBar1.setBorder(border);
content.add(progressBar1, BorderLayout.NORTH);
frame.setSize(300, 100);
frame.setVisible(true);
}
IP Scan method
IPrange netRange = new IPrange();
ArrayList<String> block = netRange.getRange();
/**
* performing ip scan
*/
@Action
public void StartIPscan()
{
String ipFrom = txtboxIPfrom.getText();
String ipTo = txtboxIPto.getText();
netRange.setFromip(ipFrom);
netRange.setToip(ipTo);
netRange.StrToIP();
netRange.calcNetwork();
/**
* ping sweep network
*/
boolean ping = false;
String ipadd = "";
ipadd = "Scanning network "+"\""+block.get(0)+"\""+"...."+"\n";
txtareaIPscan.setText(ipadd);
for(int i = 0; i < block.size(); i++)
{
try
{
int timeout = 1500;
InetAddress address = InetAddress.getByName(block.get(i));
ping = address.isReachable(timeout);
progressBar1.setValue(i);//updating progress bar
if(ping == true)
{
ipadd = block.get(i)+" is alive!"+"\n";
txtareaIPscan.append(ipadd);
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}