質問編集履歴

2

ダイアログにコンポーネントの配置記載がなかったので追記

2016/02/24 06:12

投稿

taka_miyata
taka_miyata

スコア18

test CHANGED
File without changes
test CHANGED
@@ -180,6 +180,8 @@
180
180
 
181
181
  private int progressMaximum;
182
182
 
183
+ private JPanel = panel1 = new JPanel ();
184
+
183
185
 
184
186
 
185
187
  /** コンストラクタ*/
@@ -188,6 +190,14 @@
188
190
 
189
191
  super( owner, modal );
190
192
 
193
+ jProgressBar1.setStringPainted(true);
194
+
195
+ panel1 .add(jProgressBar1);
196
+
197
+ jProgressBar1.setBounds(10, 10, 220, 30);
198
+
199
+ this.getContentPane().add(panel1 , java.awt.BorderLayout.CENTER);
200
+
191
201
  this.setPreferredSize( new Dimension( 245, 140 ) );
192
202
 
193
203
  }

1

ソースコード追加

2016/02/24 06:12

投稿

taka_miyata
taka_miyata

スコア18

test CHANGED
File without changes
test CHANGED
@@ -18,36 +18,292 @@
18
18
 
19
19
 
20
20
 
21
+ 以下実装ソースです。実際、とても長いので省略します。
22
+
23
+
24
+
25
+ UserClass : 印刷処理を利用するクラス
26
+
27
+ PrintClass : 印刷処理を行うクラス
28
+
29
+ ProgDlgClass:進捗管理ダイアログクラス
30
+
31
+
32
+
21
33
  ```java
22
34
 
35
+ /** 印刷処理を利用するクラス */
36
+
37
+ class UserClass extend JFrame {
38
+
39
+ /** 印刷処理 */
40
+
41
+ private void PrintProc ( ){
42
+
43
+ PrintClass printCl = new PrintClass();
44
+
45
+ printCl.executePrint( this );
46
+
47
+ }
48
+
49
+
50
+
51
+ }
52
+
53
+ /** 印刷処理を行うクラス */
54
+
55
+ class PrintClass {
56
+
57
+
58
+
59
+ JFrame frame;
60
+
61
+ ProgDlgClass dialog;
62
+
63
+ /** 印刷処理 */
64
+
65
+ public void executePrint( JFrame frame ) {
66
+
67
+
68
+
69
+ dialog = new ProgDlgClass( frame, false );// モーダル false
70
+
71
+
72
+
73
+ dialog.setProgressMaximum( 0 );
74
+
75
+ dialog.setProgressMaximum( 0 );
76
+
77
+ dialog.setProgressValue( dialog.getProgressMinimum() );//最小値をセット
78
+
79
+ dialog.setProgressAuto( true ); // 最初は不確定モード
80
+
81
+
82
+
23
- // "処理中"のスレッド
83
+ // 進捗表示のスレッド
24
-
84
+
25
- Thread thread = new Thread( new Runnable() {
85
+ Thread thread = new Thread( new Runnable() {
26
-
86
+
27
- @Override
87
+ @Override
28
-
88
+
29
- public void run() {
89
+ public void run() {
30
-
90
+
31
- try {
91
+ try {
32
-
92
+
33
- dialog.execute();
93
+ dialog.execute();
94
+
95
+ }
96
+
97
+ catch ( Exception e ) {
98
+
99
+ //ここで例外ログ表示
100
+
101
+ }
102
+
103
+ } );
104
+
105
+ thread.start();
106
+
107
+ displayWaiting();
108
+
109
+
110
+
111
+ // 印刷処理実行スレッド
112
+
113
+ Thread thread2 = new Thread( new Runnable() {
114
+
115
+ public void run() {
116
+
117
+ executePrint();
34
118
 
35
119
  }
36
120
 
121
+ } );
122
+
37
- catch ( Exception e ) {
123
+ thread2.start();
124
+
125
+
126
+
38
-
127
+ }
128
+
129
+
130
+
39
- //ここで例外ログ表示
131
+ /** 進捗画面の表示待ち */
132
+
133
+ private void displayWaiting() throws Exception {
134
+
135
+ for ( short i = 0; i < 300; i++ ) {
136
+
137
+ if ( dialog != null && dialog.isVisible() ) {
138
+
139
+ Thread.sleep( 100 );
140
+
141
+ return;
40
142
 
41
143
  }
42
144
 
43
- } );
44
-
45
- thread.start();
145
+ Thread.sleep( 10 );
146
+
147
+ }
148
+
149
+ }
150
+
151
+ /** 印刷データ作成 */
152
+
153
+ private void executePrint() {
154
+
155
+ for( int i = 0 ; i < ・・・ ) {
156
+
157
+ dialog.setProgressValue( i );
158
+
159
+ //印刷データ作成 こちらで、プログレスバーの値を設定し、進捗状況を管理
160
+
161
+ }
162
+
163
+ }
164
+
165
+
166
+
167
+ }
168
+
169
+
170
+
171
+ /** 進捗管理 */
172
+
173
+ public class ProgDlgClass extends JDaialg {
174
+
175
+
176
+
177
+ private JProgressBar jProgressBar1 = new JProgressBar();
178
+
179
+ private int progressMinimum;
180
+
181
+ private int progressMaximum;
182
+
183
+
184
+
185
+ /** コンストラクタ*/
186
+
187
+ public ProgDlgClass( Frame owner, boolean modal ) {
188
+
189
+ super( owner, modal );
190
+
191
+ this.setPreferredSize( new Dimension( 245, 140 ) );
192
+
193
+ }
194
+
195
+
196
+
197
+ /**
198
+
199
+ * 開始
200
+
201
+ */
202
+
203
+ public void execute() throws Exception {
204
+
205
+ if ( this.progressMaximum == 0 &&
206
+
207
+ this.progressMinimum == 0 &&
208
+
209
+ this.progressAuto == false ) {
210
+
211
+ // ここは、progressAuto = trueのため、今回は通らない
212
+
213
+ return;
214
+
215
+ }
216
+
217
+ this.setVisible( true );
218
+
219
+ }
220
+
221
+
222
+
223
+ /**プログレスバーの最大値設定 */
224
+
225
+ public void setProgressMaximum( int wkValue ) {
226
+
227
+ this.progressMaximum = wkValue;
228
+
229
+ this.jProgressBar1.setMaximum( wkValue );
230
+
231
+ }
232
+
233
+
234
+
235
+ /** プログレスバーの最小値設定*/
236
+
237
+ public void setProgressMinimum( int wkValue ) {
238
+
239
+ this.progressMinimum = wkValue;
240
+
241
+ this.jProgressBar1.setMinimum( wkValue );
242
+
243
+ }
244
+
245
+
246
+
247
+ /** プログレスバーの最小値設定*/
248
+
249
+ public int getProgressMinimum() {
250
+
251
+ return this.progressMinimum = wkValue;
252
+
253
+ }
254
+
255
+
256
+
257
+ /** プログレスバーの最小値設定*/
258
+
259
+ public int getProgressMinimum() {
260
+
261
+ return this.progressMinimum = wkValue;
262
+
263
+ }
264
+
265
+
266
+
267
+ /** プログレスバーの現在値を設定
268
+
269
+ * @param wkValue 設定しようとするプログレスバーの現在値
270
+
271
+ */
272
+
273
+ public void setProgressValue( int wkValue ) {
274
+
275
+ this.jProgressBar1.setValue( wkValue );
276
+
277
+ }
278
+
279
+
280
+
281
+ /** プログレスバーの自動処理状態を設定します。
282
+
283
+ * @param wkBool 自動処理状態 true:勝手に動作します。
284
+
285
+ */
286
+
287
+ public void setProgressAuto( boolean wkBool ) {
288
+
289
+ this.progressAuto = wkBool;
290
+
291
+ this.jProgressBar1.setIndeterminate( this.progressAuto );
292
+
293
+ this.jProgressBar1.setStringPainted( !this.progressAuto );
294
+
295
+ }
296
+
297
+ }
46
298
 
47
299
  ```
48
300
 
49
301
 
50
302
 
303
+ PrintClass の executePrintがexecuteされ、ProgDlgClass が表示された時に例外が発生。
304
+
305
+ 終了は別途ボタンが有り、ボタン押下でdispose()が実行されます。
306
+
51
307
 
52
308
 
53
309
  以下 例外内容