Biblioteca Java - Blame information for rev 28

Subversion Repositories:
Rev:
Rev Author Line No. Line
28 mihai 1 /*
2  * NumaratorWindowT.java
3  */
4 package exemple.fire.thread;
5  
6 import javax.swing.JTextField;
7  
8 /**
9  * Class created by @author Mihai HULEA at Feb 12, 2005.
10  *
11  * This class is part of the labs project.
12  *
13  */
14 /*
15  * NumaratorT.java
16  */
17 public class NumaratorWindowT extends Thread{
18  
19     int nr;
20     boolean active = true;
21     JTextField tf;
22     /**
23      * Constructorul clasei.
24      * @param name reprezinta numele firulul
25      */
26     public NumaratorWindowT(String name){
27         //metoda seteaza numele unui fir de executie
28         this.setName(name);
29     }
30  
31     /**
32      * In momentul startarii unui fir de exectuie este apelata si executata in cadrul
33      * firului metoda run().
34      */
35     public void run(){
36  
37         while(active){
38             nr++;
39             System.out.println("Thread "+this.getName()+" counter = "+nr);
40             tf.setText(""+nr);
41             try {
42                 //dupa fiecare incrementare a firului se realizeaza opauza de 500 milisecunde
43                 Thread.sleep(500);
44             } catch (InterruptedException e) {
45  
46                 e.printStackTrace();
47             }
48         }//.while
49     }
50  
51     public void setTextField(JTextField tf){
52         this.tf = tf;
53     }
54  
55     public static void main(String[] args) {
56  
57         ThreadJFrame f = new ThreadJFrame();
58  
59         //declara 3 variabile de tip NumaratorT
60         NumaratorWindowT n1,n2,n3;
61  
62         //construieste obiectele n1, n2 si n3
63         n1 = new NumaratorWindowT("Fir 1");
64         n2 = new NumaratorWindowT("Fir 1");
65         n3 = new NumaratorWindowT("Fir 1");
66  
67         f.addThreadCounterTextbox(n1);
68         f.addThreadCounterTextbox(n2);
69         f.addThreadCounterTextbox(n3);
70  
71         f.setVisible(true);
72  
73  
74         //starteaza cele 3 fire de executie. Startarea unui fir de executie se face
75         // apelandmetoda start
76         n1.start();
77         n2.start();
78         n3.start();
79  
80     }
81 }