如何实现进度条? Swing里面有进度条的控件。实现你的要求大致思路为:你的程序中每对数据库进行一个步骤的操作就更新一下进度条就行了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没有进度条能真实反映进度的,像ie的statusbar,明明一个网页连不上,他也会有进度。所以你自己大致做一下,只要保证最后完成时是100% swing的好象有点问题,普通的浏览器不支持JApplet的如果不能真实的反映进度,用一个动画图片来实现不是更加容易!各位还有没有其它高见? 大侠们,怎么都不说话呀,帮帮我啊,SOS!!! 修改一下/** * @version 1.00 1999-07-17 * @author Cay Horstmann */import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;public class ProgressBarTest{ public static void main(String[] args) { JFrame frame = new ProgressBarFrame(); frame.show(); }}class ProgressBarFrame extends JFrame{ public ProgressBarFrame() { setTitle("ProgressBarTest"); setSize(300, 200); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); Container contentPane = getContentPane(); // this text area holds the activity output textArea = new JTextArea(); // set up panel with button and progress bar JPanel panel = new JPanel(); startButton = new JButton("Start"); progressBar = new JProgressBar(); progressBar.setStringPainted(true); panel.add(startButton); panel.add(progressBar); contentPane.add(new JScrollPane(textArea), "Center"); contentPane.add(panel, "South"); // set up the button action startButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { progressBar.setMaximum(1000); activity = new SimulatedActivity(1000); activity.start(); activityMonitor.start(); startButton.setEnabled(false); } }); // set up the timer action activityMonitor = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent event) { int current = activity.getCurrent(); // show progress textArea.append(current + "\n"); progressBar.setValue(current); // check if task is completed if (current == activity.getTarget()) { activityMonitor.stop(); startButton.setEnabled(true); } } }); } private Timer activityMonitor; private JButton startButton; private JProgressBar progressBar; private JTextArea textArea; private SimulatedActivity activity;}class SimulatedActivity extends Thread{ public SimulatedActivity(int t) { current = 0; target = t; } public int getTarget() { return target; } public int getCurrent() { return current; } public void run() { while (current < target && !interrupted()) { try { sleep(100); } catch(InterruptedException e) { return; } current++; } } private int current; private int target;} 这个还是用的swing构件啊,在浏览器上是没发显示出来的各位大侠,还有高招吗? 你可以用AWT构件自己做一个,AWT浏览器肯定是支持的。很简单的。 我是想知道用javascript可以实现吗?各位有无原码 java继承中,为什么成员变量可以隐藏,而方法不可以了?反过来,为什么方法可以覆盖而成员变量不可以了? java语言聊天 有关打开网页的问题? 怎样用java调用dll? 寻找一个JAVA方法 找BUG散分了啊! 请问java.util.ResourceBundle的作用和用法,怎么取一个.conf文件的key的值. 如何合成变量名? 请问如何学习JAVA,大家推荐我几本书吧! java中除Canvas类可以画图外,还有其它类吗? 寻找java编程高手做为合作伙伴! 关于jar的问题
如果不能真实的反映进度,用一个动画图片来实现不是更加容易!
各位还有没有其它高见?
* @version 1.00 1999-07-17
* @author Cay Horstmann
*/import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;public class ProgressBarTest
{ public static void main(String[] args)
{ JFrame frame = new ProgressBarFrame();
frame.show();
}
}class ProgressBarFrame extends JFrame
{ public ProgressBarFrame()
{ setTitle("ProgressBarTest");
setSize(300, 200);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} ); Container contentPane = getContentPane(); // this text area holds the activity output
textArea = new JTextArea(); // set up panel with button and progress bar JPanel panel = new JPanel();
startButton = new JButton("Start");
progressBar = new JProgressBar();
progressBar.setStringPainted(true);
panel.add(startButton);
panel.add(progressBar);
contentPane.add(new JScrollPane(textArea), "Center");
contentPane.add(panel, "South"); // set up the button action startButton.addActionListener(
new ActionListener()
{ public void actionPerformed(ActionEvent event)
{ progressBar.setMaximum(1000);
activity = new SimulatedActivity(1000);
activity.start();
activityMonitor.start();
startButton.setEnabled(false);
}
});
// set up the timer action activityMonitor = new Timer(500,
new ActionListener()
{ public void actionPerformed(ActionEvent event)
{ int current = activity.getCurrent(); // show progress
textArea.append(current + "\n");
progressBar.setValue(current); // check if task is completed
if (current == activity.getTarget())
{ activityMonitor.stop();
startButton.setEnabled(true);
}
}
});
} private Timer activityMonitor;
private JButton startButton;
private JProgressBar progressBar;
private JTextArea textArea;
private SimulatedActivity activity;
}class SimulatedActivity extends Thread
{ public SimulatedActivity(int t)
{ current = 0;
target = t;
} public int getTarget()
{ return target;
} public int getCurrent()
{ return current;
} public void run()
{ while (current < target && !interrupted())
{ try
{ sleep(100);
}
catch(InterruptedException e)
{ return;
}
current++;
}
} private int current;
private int target;
}
各位大侠,还有高招吗?
很简单的。
各位有无原码