您的位置:首页 > 产品设计 > UI/UE

JAVA GUI学习 - JProgressBar进度条组件摘录

2013-09-22 10:53 459 查看
public class JProgressBarTest  extends JFrame{

public JProgressBarTest() {
super();
setTitle("表格");
setBounds(100,100,350,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton("           ");
final JButton button2 = new JButton("完成");
button2.setEnabled(false); //初始化时不可用
button.setBounds(100,100,100,100);

final JProgressBar progressBar = new JProgressBar();
progressBar.setStringPainted(true);  //显示提示信息
progressBar.setIndeterminate(false);   //确定进度的进度条
//progressBar.setIndeterminate(true);   //不确定进度的进度条
//        progressBar.setString("升级中...");    //确定信息时加上此条,则提示升级中,没有%比,如是不加上这个,则会提示%
setLayout(new FlowLayout(2,10,10));
getContentPane().add(button);  //布局处理
getContentPane().add(button2);  //布局处理
getContentPane().add(progressBar);  //布局处理
new Progress(progressBar,button2).start();   //自定义类progress
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JProgressBarTest jProgressBarTest = new JProgressBarTest();
jProgressBarTest.setVisible(true);
}

}
class Progress extends Thread{//自定义类progress
private final int []progressValue = {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,
62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100};
private JProgressBar progressBar;
private JButton button;
public Progress(JProgressBar progressBar,JButton button)
{
this.progressBar = progressBar;
this.button =button;
}
public void run()
{
for(int i=0;i<progressValue.length;i++)
{
try
{
Thread.sleep(100);
}catch(Exception e)
{
e.printStackTrace();
}
progressBar.setValue(progressValue[i]);  //进度值
}
progressBar.setIndeterminate(false);  //采用确定的进度条
//progressBar.setIndeterminate(true);   //不确定进度的进度条
progressBar.setString("升级完成.");  //提示信息
button.setEnabled(true);  //按钮可用
}
}


摘录自:null
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: