/Users/lyon/j4p/src/bookExamples/ch18Swing/AtomicExamples.java

1    package bookExamples.ch18Swing; 
2     
3    import gui.In; 
4    import gui.run.RunButton; 
5    import gui.In; 
6     
7    import javax.swing.*; 
8    import javax.swing.event.ChangeListener; 
9    import javax.swing.event.ChangeEvent; 
10   import javax.swing.colorchooser.ColorSelectionModel; 
11   import java.awt.*; 
12    
13   /** 
14    * DocJava, Inc. 
15    * http://www.docjava.com 
16    * Programmer: dlyon 
17    * Date: Sep 22, 2004 
18    * Time: 8:16:02 PM 
19    */ 
20   public class AtomicExamples { 
21       public static void main(String[] args) { 
22           progressBarExample(); 
23       } 
24    
25       private static void progressBarExample() { 
26           // for homework, use the JColorChooser to 
27           // alter the foreground color of the JProgressBar. 
28           // in the ch18 package. 
29           final JColorChooser jcc = new JColorChooser(); 
30           final JProgressBar jp = new JProgressBar(); 
31           final JLabel jl = new JLabel("% done=" + 0); 
32           jp.setMinimum(0); 
33           jp.setMaximum(100); 
34           JDialog jd = new JDialog(); 
35           Container c = jd.getContentPane(); 
36           c.add(new RunButton("setForeground") { 
37               public void run() { 
38                   jp.setForeground(jcc.getColor()); 
39               } 
40           }); 
41           final ColorSelectionModel csm = jcc.getSelectionModel(); 
42           csm.addChangeListener(new ChangeListener() { 
43               public void stateChanged(ChangeEvent ce) { 
44                   jl.setForeground(csm.getSelectedColor()); 
45               } 
46           }); 
47           c.add(new RunButton("setBackground") { 
48               public void run() { 
49                   jp.setBackground(jcc.getColor()); 
50               } 
51           }); 
52           c.add(jp); 
53           c.add(jl); 
54           c.add(jcc); 
55           c.setLayout(new FlowLayout()); 
56           jd.pack(); 
57           jd.show(); 
58           for (int i = 0; i <= 100; i++) { 
59               jp.setValue(i); 
60               jl.setText("% done=" + i); 
61               try { 
62                   Thread.sleep(500); 
63               } catch (InterruptedException e) { 
64                   e.printStackTrace(); 
65               } 
66           } 
67       } 
68    
69       private static void ex1() { 
70           String name = In.getString("what is your name?"); 
71           int age = In.getInt("enter an age between 6 and 110", 6, 110); 
72           In.message("Hello " + name + " you are " + age + " old!"); 
73       } 
74   } 
75