2019独角兽企业重金招聘Python工程师标准>>>
一个矩形组件
Method | Describle |
JProgrssBar() | 不带进度字符,最小值0最大值100的水平进度条 |
JProgressBar(int orient) | VERTICAL/HORIZONTAL |
JProgressBar(int in,int max) | 指定最大最小的水平进度条 |
JProgressBar(int orient,int min, int max) | 指定方向,最大最小 |
example
package Eleven;import javax.swing.JFrame;import javax.swing.JProgressBar;import javax.swing.WindowConstants;import javax.swing.WindowConstants;import javax.swing.JProgressBar;import java.awt.BorderLayout;import javax.swing.JLabel;public class Progress extends JFrame {private static JProgressBar progressBar;public Progress(){setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);progressBar = new JProgressBar();//void javax.swing.JProgressBar.setStringPainted(boolean b)//true:显示进度%xprogressBar.setStringPainted(true);
//void java.awt.Container.add(Component comp, Object constraints)getContentPane().add(progressBar,BorderLayout.CENTER);setBounds(100,100,300,78);final JLabel label = new JLabel();getContentPane().add(label,BorderLayout.NORTH);label.setText("loading...");setVisible(true);}public static void main(String[] args){new Progress();
//void javax.swing.JProgressBar.setIndeterminate(boolean newValue)progressBar.setIndeterminate(true);for(int i = 0;i <= 100;i++){try{Thread.sleep(100);}catch(InterruptedException e){e.printStackTrace();}//void javax.swing.JProgressBar.setValue(int n)progressBar.setValue(i);}progressBar.setIndeterminate(true);//进度条满显示满格progressBar.setString("Done");}
}