質問編集履歴
2
ソース全文、使用ツールバージョン追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,32 +10,121 @@
|
|
10
10
|
|
11
11
|
そこで、以下のソースのように、setIconにnullを指定して画像を消した後に、次の画像を表示しようとしたのですが、setIconにnullを指定しても画像がクリアされません。
|
12
12
|
|
13
|
+
以下のクラスを、ダミーのmainから呼び出しています。
|
13
14
|
```ここに言語を入力
|
14
|
-
int index = 1;
|
15
|
-
|
15
|
+
package customwaitanimation;
|
16
16
|
|
17
|
+
import java.awt.Color;
|
18
|
+
import java.awt.Container;
|
19
|
+
import java.util.logging.Level;
|
20
|
+
import java.util.logging.Logger;
|
21
|
+
import javax.swing.ImageIcon;
|
22
|
+
import javax.swing.JFrame;
|
23
|
+
import javax.swing.JLabel;
|
24
|
+
import javax.swing.JPanel;
|
17
25
|
|
26
|
+
public class CustomWaitAnimation extends Thread {
|
27
|
+
|
28
|
+
private boolean running;
|
29
|
+
|
30
|
+
private JFrame frame;
|
31
|
+
private JPanel panel;
|
32
|
+
private JLabel label1;
|
33
|
+
private Container contentPane;
|
34
|
+
|
35
|
+
private static final int ANIMATION_FRAMES = 10;
|
36
|
+
|
18
|
-
//
|
37
|
+
// コンストラクタ
|
38
|
+
public CustomWaitAnimation() {
|
39
|
+
//
|
40
|
+
this.running = true;
|
41
|
+
|
42
|
+
//
|
43
|
+
this.frame = new JFrame();
|
44
|
+
|
45
|
+
this.frame.setSize(110, 110);
|
46
|
+
this.frame.setAlwaysOnTop(true);
|
47
|
+
this.frame.setLocationRelativeTo(null);
|
48
|
+
|
49
|
+
this.frame.setUndecorated(true);
|
50
|
+
this.frame.setBackground(new Color(0, 0, 0, 0));
|
51
|
+
|
19
|
-
|
52
|
+
this.panel = new JPanel();
|
20
|
-
String filename = "loading" + String.format("%02d", index) + ".png";
|
21
|
-
ImageIcon icon = new ImageIcon(filename);
|
22
|
-
|
53
|
+
this.panel.setBackground(new Color(0, 0, 0, 0));
|
23
54
|
|
24
|
-
|
55
|
+
ImageIcon icon = new ImageIcon("loading01.png");
|
25
|
-
|
56
|
+
this.label1 = new JLabel();
|
57
|
+
this.label1.setIcon(icon);
|
58
|
+
|
26
|
-
|
59
|
+
this.panel.add(this.label1);
|
60
|
+
|
61
|
+
this.contentPane = this.frame.getContentPane();
|
62
|
+
this.contentPane.add(this.panel);
|
63
|
+
|
27
64
|
}
|
65
|
+
|
66
|
+
@Override
|
67
|
+
public void run() {
|
68
|
+
|
69
|
+
this.frame.setVisible(true);
|
70
|
+
|
71
|
+
int index = 1;
|
72
|
+
while(this.running) {
|
73
|
+
|
74
|
+
//画像を消したあと次の画像をセットする
|
75
|
+
this.label1.setIcon(null);
|
76
|
+
String filename = "loading" + String.format("%02d", index) + ".png";
|
77
|
+
ImageIcon icon = new ImageIcon(filename);
|
78
|
+
this.label1.setIcon(icon);
|
79
|
+
|
80
|
+
//ファイル名のインデックスをインクリメントorリセット
|
81
|
+
if(index >= ANIMATION_FRAMES) {
|
82
|
+
index = 1;
|
83
|
+
}
|
28
|
-
|
84
|
+
else {
|
29
|
-
|
85
|
+
index ++;
|
86
|
+
}
|
87
|
+
|
88
|
+
//0.1秒更新
|
89
|
+
try {
|
90
|
+
sleep(100);
|
91
|
+
} catch (InterruptedException ex) {
|
92
|
+
Logger.getLogger(CustomWaitAnimation.class.getName()).log(Level.SEVERE, null, ex);
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
this.frame.setVisible(false);
|
98
|
+
|
30
99
|
}
|
100
|
+
|
101
|
+
public void stopRunning() {
|
102
|
+
//
|
103
|
+
this.running = false;
|
104
|
+
}
|
105
|
+
|
106
|
+
}
|
107
|
+
```
|
31
108
|
|
109
|
+
ダミーのmain
|
110
|
+
```ここに言語を入力
|
111
|
+
import customwaitanimation.CustomWaitAnimation;
|
112
|
+
|
32
|
-
|
113
|
+
public class TestMain {
|
114
|
+
|
115
|
+
public static void main(String[] args) {
|
116
|
+
|
117
|
+
CustomWaitAnimation w = new CustomWaitAnimation();
|
118
|
+
|
119
|
+
w.start();
|
120
|
+
|
33
|
-
|
121
|
+
try{
|
34
|
-
|
122
|
+
Thread.sleep(10000);
|
35
|
-
|
123
|
+
}catch(InterruptedException e){}
|
124
|
+
|
36
|
-
|
125
|
+
w.stopRunning();
|
37
126
|
}
|
38
|
-
|
127
|
+
|
39
128
|
}
|
40
129
|
```
|
41
130
|
|
@@ -44,4 +133,8 @@
|
|
44
133
|
|
45
134
|
###
|
46
135
|
|
47
|
-
使用している
|
136
|
+
使用しているツールのバージョンは、
|
137
|
+
・Windows10 pro
|
138
|
+
・NetBeans 8.1
|
139
|
+
・Java 1.7.0
|
140
|
+
です。
|
1
画像をアニメーションに変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,7 +3,10 @@
|
|
3
3
|
###
|
4
4
|
JlabelのsetIconにImageIconを、順番に指定することでダミー画像をアニメーションさせることは成功しているのですが、半透明のpngファイルを使用しているためか、指定するたびに以下のように画像が合成されてしまいます。
|
5
5
|
|
6
|
+
半透明
|
7
|
+

|
8
|
+
不透明
|
6
|
-

|
7
10
|
|
8
11
|
そこで、以下のソースのように、setIconにnullを指定して画像を消した後に、次の画像を表示しようとしたのですが、setIconにnullを指定しても画像がクリアされません。
|
9
12
|
|