/Users/lyon/j4p/src/bookExamples/ch13Threads/Exception.java

1    package bookExamples.ch13Threads; 
2     
3    import java.awt.*; 
4    import java.util.Vector; 
5     
6    class RuntimeExceptionExample extends RuntimeException { 
7     
8        public RuntimeExceptionExample(String s) { 
9            super(s); 
10       } 
11    
12       public RuntimeExceptionExample() { 
13       } 
14   } 
15    
16   class CounterExample { 
17    
18       static Thread ta[] = new Thread[100]; 
19    
20       public static void main(String args[]) { 
21           for (int i = 0; i < ta.length; i++) { 
22               ta[i] = new Thread(new RunCounter()); 
23               ta[i].start(); 
24           } 
25    
26       } 
27    
28   } 
29    
30   class RunCounter implements Runnable { 
31    
32   //Thread t = new Thread(this); 
33    
34       private int i = 0; 
35    
36       public static void main(String args[]) { 
37    
38           RunCounter c = new RunCounter(); 
39    
40   //c.t.start(); 
41    
42       } 
43    
44       public void run() { 
45    
46           for (int i = 0; i < 10; i++) 
47    
48               System.out.println(i); 
49    
50       } 
51   } 
52    
53   class CustomerTestFrame extends Frame { 
54    
55       static Vector customerNames = new Vector(); 
56    
57       private static int m = 0; 
58    
59       synchronized public void setM(int _m) { 
60           m = _m; 
61       } 
62    
63       public void init() { 
64           setSize(200, 200); 
65           setVisible(true); 
66       } 
67    
68       synchronized public void paint(Graphics g) { 
69    
70           g.drawString("Hello World!" + m++, 
71    
72                   100, 100); 
73    
74           repaint(1000); 
75    
76       } 
77    
78       public static void main(String args[]) { 
79    
80           CustomerTestFrame 
81    
82                   f = new CustomerTestFrame(); 
83    
84           f.init(); 
85    
86       } 
87    
88    
89       public static void exceptionalExample(String args[]) { 
90    
91           System.out.println("Hello World!"); 
92           customerNames.add("Tom"); 
93           customerNames.add("Dick"); 
94           customerNames.add("Harry"); 
95           customerNames.add(new RuntimeExceptionExample("Hello World!")); 
96    
97           for (int i = 0; i < customerNames.size(); i++) { 
98    
99               System.out.println(customerNames.elementAt(i)); 
100   
101          } 
102   
103  //try { 
104   
105  // int i = 1/ 0; 
106   
107  //} 
108   
109  //catch ( 
110   
111  // ArithmeticException e) { 
112   
113  // ha ha arian 4 blows up!! 
114   
115  //} 
116   
117      } 
118   
119  } 
120