/Users/lyon/j4p/src/gui/dialogs/ProgressDialog.java

1    package gui.dialogs; 
2     
3    import javax.swing.*; 
4    import java.awt.*; 
5     
6    /** 
7     * Copyright DocJava, inc. User: lyon 
8     * <p/> 
9     * Date: Nov 24, 2004 
10    * <p/> 
11    * Time: 9:33:06 AM 
12    */ 
13   public class ProgressDialog extends JDialog { 
14       final JProgressBar jp = new JProgressBar(); 
15       final JLabel jl = new JLabel("% done=" + 0); 
16       Container c = getContentPane(); 
17    
18       public ProgressDialog() { 
19           c.setLayout(new GridLayout(0,1)); 
20           c.add(jp); 
21           c.add(jl); 
22           jp.setMinimum(0); 
23           jp.setMaximum(100); 
24       } 
25       public void incrementValue(int i) { 
26           setValue(jp.getValue() + i); 
27       } 
28       public void setValue(int i){ 
29           jp.setValue(i); 
30           jl.setText("% done=" + i); 
31       } 
32    
33       public Dimension getPreferredSize() { 
34           return new Dimension(100,100); 
35       } 
36    
37       public Dimension getMinimumSize() { 
38           return getPreferredSize(); 
39       } 
40       public static void main(String[] args) { 
41           ProgressDialog pd = new ProgressDialog(); 
42           pd.setSize(200,200); 
43           pd.show(); 
44           for (int i = 0; i <= 100; i++) { 
45               pd.setValue(i); 
46               sleep(); 
47           } 
48       } 
49    
50       private static void sleep() { 
51           try { 
52               Thread.sleep(250); 
53           } catch (InterruptedException e) { 
54               e.printStackTrace(); 
55           } 
56       } 
57   } 
58