?? testjprogressbar.java
字號:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class TestJProgressBar
{
JFrame frame = new JFrame("測試進度條");
//創建一條垂直進度條
JProgressBar bar = new JProgressBar(JProgressBar.VERTICAL );
JCheckBox indeterminate = new JCheckBox("不確定進度");
JCheckBox noBorder = new JCheckBox("不繪制邊框");
public void init()
{
Box box = new Box(BoxLayout.Y_AXIS);
box.add(indeterminate);
box.add(noBorder);
frame.setLayout(new FlowLayout());
frame.add(box);
//把進度條添加到JFrame窗口中
frame.add(bar);
//設置進度條的最大值和最小值
bar.setMinimum(0);
bar.setMaximum(100);
//設置在進度條中繪制完成百分比
bar.setStringPainted(true);
noBorder.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
//根據該選擇框決定是否繪制進度條的邊框
bar.setBorderPainted(!noBorder.isSelected());
}
});
indeterminate.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
//設置該進度條的進度是否確定
bar.setIndeterminate(indeterminate.isSelected());
bar.setStringPainted(!indeterminate.isSelected());
}
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
//采用循環方式來不斷改變進度條的完成進度
for (int i = 0 ; i <= 100 ; i++)
{
//改變進度條的完成進度
bar.setValue(i);
try
{
Thread.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public static void main(String[] args)
{
new TestJProgressBar().init();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -