KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DebuggerTestApplication


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  * The Original Software is NetBeans.
15  * The Initial Developer of the Original Software is Sun Microsystems, Inc.
16  * Portions created by Sun Microsystems, Inc. are Copyright (C) 2003
17  * All Rights Reserved.
18  *
19  * Contributor(s): Sun Microsystems, Inc.
20  */

21
22 public class DebuggerTestApplication extends javax.swing.JFrame JavaDoc {
23
24     /** Creates new form TestApp */
25     public DebuggerTestApplication() {
26         this.setTitle("Debugger Test Application");
27         initComponents();
28
29         counterThread = new Thread JavaDoc(new Runnable JavaDoc() {
30             public void run() {
31                 Thread JavaDoc thisThread = Thread.currentThread();
32                 while (counterThread == thisThread) {
33                     updateCounter();
34                     try {
35                         Thread.currentThread().sleep(1000);
36                         if (counterThreadSuspended) {
37                             synchronized(counterThread) {
38                                 while (counterThreadSuspended) {
39                                     counterThread.wait();
40                                 }
41                             }
42                         }
43                         
44                     } catch (InterruptedException JavaDoc ie) {
45                         ie.printStackTrace();
46                     }
47                 }
48             }
49         });
50         counterThread.setName("counterThread");
51         counterThread.start();
52         
53     }
54     
55     /** This method is called from within the constructor to
56      * initialize the form.
57      * WARNING: Do NOT modify this code. The content of this method is
58      * always regenerated by the Form Editor.
59      */

60     private void initComponents() {//GEN-BEGIN:initComponents
61
jPanel1 = new javax.swing.JPanel JavaDoc();
62         jButton1 = new javax.swing.JButton JavaDoc();
63         jButton2 = new javax.swing.JButton JavaDoc();
64         jLabel1 = new javax.swing.JLabel JavaDoc();
65         jProgressBar1 = new javax.swing.JProgressBar JavaDoc();
66         jProgressBar1.setMaximum(MAX_COUNT);
67
68         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
69             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
70                 exitForm(evt);
71             }
72         });
73
74         jButton1.setText("Stop");
75         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
76             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
77                 jButton1ActionPerformed(evt);
78             }
79         });
80
81         jPanel1.add(jButton1);
82
83         jButton2.setText("Clear");
84         jButton2.addActionListener(new java.awt.event.ActionListener JavaDoc() {
85             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
86                 jButton2ActionPerformed(evt);
87             }
88         });
89
90         jPanel1.add(jButton2);
91
92         getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
93
94         jLabel1.setFont(new java.awt.Font JavaDoc("Dialog", 1, 36));
95         jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
96         jLabel1.setText("jLabel1");
97         getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER);
98
99         getContentPane().add(jProgressBar1, java.awt.BorderLayout.NORTH);
100
101         pack();
102     }//GEN-END:initComponents
103

104     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
105
if (!counterThreadSuspended) {
106             counterThreadSuspended = !counterThreadSuspended;
107             jButton1.setText("Start");
108         } else {
109             synchronized(counterThread) {
110                 counterThreadSuspended = !counterThreadSuspended;
111                 counterThread.notify();
112                 jButton1.setText("Stop");
113             }
114             
115         }
116     }//GEN-LAST:event_jButton1ActionPerformed
117

118     private void jButton2ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton2ActionPerformed
119
counter = 0;
120         jLabel1.setText(String.valueOf(counter));
121     }//GEN-LAST:event_jButton2ActionPerformed
122

123     private void updateCounter() {
124         counter = (counter < MAX_COUNT) ? ++counter : 0 ;
125         jLabel1.setText(String.valueOf(counter));
126         jProgressBar1.setValue(counter);
127     }
128     
129     /** Exit the Application */
130     private void exitForm(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_exitForm
131
System.exit(0);
132     }//GEN-LAST:event_exitForm
133

134     
135     /**
136      * @param args the command line arguments
137      */

138     public static void main(String JavaDoc args[]) {
139         new DebuggerTestApplication().show();
140     }
141     
142     // Variables declaration - do not modify//GEN-BEGIN:variables
143
private javax.swing.JButton JavaDoc jButton1;
144     private javax.swing.JButton JavaDoc jButton2;
145     private javax.swing.JLabel JavaDoc jLabel1;
146     private javax.swing.JPanel JavaDoc jPanel1;
147     private javax.swing.JProgressBar JavaDoc jProgressBar1;
148     // End of variables declaration//GEN-END:variables
149
private Thread JavaDoc counterThread;
150     public volatile boolean counterThreadSuspended = false;
151     private int counter = 0;
152     
153     private static final int MAX_COUNT = 13;
154     
155 }
156
Popular Tags