質問編集履歴

2

ソース全文、使用ツールバージョン追加

2016/08/10 03:00

投稿

taxshi
taxshi

スコア7

test CHANGED
File without changes
test CHANGED
@@ -22,57 +22,191 @@
22
22
 
23
23
 
24
24
 
25
+ 以下のクラスを、ダミーのmainから呼び出しています。
26
+
25
27
  ```ここに言語を入力
26
28
 
27
- int index = 1;
28
-
29
- while(this.running) {
30
-
31
-
32
-
33
-
34
-
35
- //画像を消したあと次の画像をセットする
36
-
37
- this.label1.setIcon(null);
38
-
39
- String filename = "loading" + String.format("%02d", index) + ".png";
40
-
41
- ImageIcon icon = new ImageIcon(filename);
42
-
43
- this.label1.setIcon(icon);
44
-
45
-
46
-
47
- //ファイル名のインデックスをインクリメントorリセット
48
-
49
- if(index >= 10) {
50
-
51
- index = 1;
52
-
53
- }
54
-
55
- else {
56
-
57
- index ++;
58
-
59
- }
60
-
61
-
62
-
63
- //0.1秒更新
64
-
65
- try {
66
-
67
- sleep(100);
68
-
69
- } catch (InterruptedException ex) {
70
-
71
- Logger.getLogger(CustomWaitAnimation.class.getName()).log(Level.SEVERE, null, ex);
72
-
73
- }
74
-
75
-
29
+ package customwaitanimation;
30
+
31
+
32
+
33
+ import java.awt.Color;
34
+
35
+ import java.awt.Container;
36
+
37
+ import java.util.logging.Level;
38
+
39
+ import java.util.logging.Logger;
40
+
41
+ import javax.swing.ImageIcon;
42
+
43
+ import javax.swing.JFrame;
44
+
45
+ import javax.swing.JLabel;
46
+
47
+ import javax.swing.JPanel;
48
+
49
+
50
+
51
+ public class CustomWaitAnimation extends Thread {
52
+
53
+
54
+
55
+ private boolean running;
56
+
57
+
58
+
59
+ private JFrame frame;
60
+
61
+ private JPanel panel;
62
+
63
+ private JLabel label1;
64
+
65
+ private Container contentPane;
66
+
67
+
68
+
69
+ private static final int ANIMATION_FRAMES = 10;
70
+
71
+
72
+
73
+ // コンストラクタ
74
+
75
+ public CustomWaitAnimation() {
76
+
77
+ //
78
+
79
+ this.running = true;
80
+
81
+
82
+
83
+ //
84
+
85
+ this.frame = new JFrame();
86
+
87
+
88
+
89
+ this.frame.setSize(110, 110);
90
+
91
+ this.frame.setAlwaysOnTop(true);
92
+
93
+ this.frame.setLocationRelativeTo(null);
94
+
95
+
96
+
97
+ this.frame.setUndecorated(true);
98
+
99
+ this.frame.setBackground(new Color(0, 0, 0, 0));
100
+
101
+
102
+
103
+ this.panel = new JPanel();
104
+
105
+ this.panel.setBackground(new Color(0, 0, 0, 0));
106
+
107
+
108
+
109
+ ImageIcon icon = new ImageIcon("loading01.png");
110
+
111
+ this.label1 = new JLabel();
112
+
113
+ this.label1.setIcon(icon);
114
+
115
+
116
+
117
+ this.panel.add(this.label1);
118
+
119
+
120
+
121
+ this.contentPane = this.frame.getContentPane();
122
+
123
+ this.contentPane.add(this.panel);
124
+
125
+
126
+
127
+ }
128
+
129
+
130
+
131
+ @Override
132
+
133
+ public void run() {
134
+
135
+
136
+
137
+ this.frame.setVisible(true);
138
+
139
+
140
+
141
+ int index = 1;
142
+
143
+ while(this.running) {
144
+
145
+
146
+
147
+ //画像を消したあと次の画像をセットする
148
+
149
+ this.label1.setIcon(null);
150
+
151
+ String filename = "loading" + String.format("%02d", index) + ".png";
152
+
153
+ ImageIcon icon = new ImageIcon(filename);
154
+
155
+ this.label1.setIcon(icon);
156
+
157
+
158
+
159
+ //ファイル名のインデックスをインクリメントorリセット
160
+
161
+ if(index >= ANIMATION_FRAMES) {
162
+
163
+ index = 1;
164
+
165
+ }
166
+
167
+ else {
168
+
169
+ index ++;
170
+
171
+ }
172
+
173
+
174
+
175
+ //0.1秒更新
176
+
177
+ try {
178
+
179
+ sleep(100);
180
+
181
+ } catch (InterruptedException ex) {
182
+
183
+ Logger.getLogger(CustomWaitAnimation.class.getName()).log(Level.SEVERE, null, ex);
184
+
185
+ }
186
+
187
+
188
+
189
+ }
190
+
191
+
192
+
193
+ this.frame.setVisible(false);
194
+
195
+
196
+
197
+ }
198
+
199
+
200
+
201
+ public void stopRunning() {
202
+
203
+ //
204
+
205
+ this.running = false;
206
+
207
+ }
208
+
209
+
76
210
 
77
211
  }
78
212
 
@@ -80,6 +214,50 @@
80
214
 
81
215
 
82
216
 
217
+ ダミーのmain
218
+
219
+ ```ここに言語を入力
220
+
221
+ import customwaitanimation.CustomWaitAnimation;
222
+
223
+
224
+
225
+ public class TestMain {
226
+
227
+
228
+
229
+ public static void main(String[] args) {
230
+
231
+
232
+
233
+ CustomWaitAnimation w = new CustomWaitAnimation();
234
+
235
+
236
+
237
+ w.start();
238
+
239
+
240
+
241
+ try{
242
+
243
+ Thread.sleep(10000);
244
+
245
+ }catch(InterruptedException e){}
246
+
247
+
248
+
249
+ w.stopRunning();
250
+
251
+ }
252
+
253
+
254
+
255
+ }
256
+
257
+ ```
258
+
259
+
260
+
83
261
  nullを指定すると、画像がクリアされるという認識だったのですが、間違っているでしょうか?
84
262
 
85
263
  また、このような状況になった方や、回避策をご存知の方はいらっしゃらないでしょうか?
@@ -90,4 +268,12 @@
90
268
 
91
269
 
92
270
 
93
- 使用しているJavaのバージョンは、1.7.0です。
271
+ 使用しているツールのバージョンは、
272
+
273
+ ・Windows10 pro
274
+
275
+ ・NetBeans 8.1
276
+
277
+ ・Java 1.7.0
278
+
279
+ です。

1

画像をアニメーションに変更

2016/08/10 03:00

投稿

taxshi
taxshi

スコア7

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,13 @@
8
8
 
9
9
 
10
10
 
11
+ 半透明
12
+
13
+ ![イメージ説明](8c9bbdd2789cfc80f928b62af19a771b.gif)
14
+
15
+ 不透明
16
+
11
- ![イメージ説明](2ed14fb61a464578b86c99d885cb8cc4.png)
17
+ ![イメージ説明](b84c1d4b355e957546dcfe3878770173.gif)
12
18
 
13
19
 
14
20