質問編集履歴
1
コード内容
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,161 +8,53 @@
|
|
8
8
|
|
9
9
|
(本当は、パネル(1)は非表示ではなく、破棄でも良いのですが、コードがわかりませんでした。)
|
10
10
|
|
11
|
-
パネル(2)にpng画像が入っており、画像が10pxほど上下に動くようにしたいです。
|
11
|
+
パネル(2)にpng画像が入っており、画像が10pxほど上下に動くようにしたいです。
|
12
|
+
|
13
|
+
また、ちらつきも無くしたいです。
|
12
14
|
|
13
15
|
|
14
16
|
|
15
|
-
|
17
|
+
Graphics gに画像を入れる場合、直接その画面に表示してアニメーションを起こすことはできたのですが、
|
16
18
|
|
19
|
+
後で表示する方法がわかりませんでした。
|
20
|
+
|
21
|
+
ImageIconの場合はLabelに入れていますが、動きませんでした。
|
22
|
+
|
23
|
+
|
24
|
+
|
17
|
-
BufferedImageの場合と、ImageIconの場合で試してますが、パネル(2)の画像が動かなかったり、出てこない、または動いても2枚重ねになってしまいます。
|
25
|
+
BufferedImage(Graphics g)の場合と、ImageIconの場合で試してますが、パネル(2)の画像が動かなかったり、出てこない、または動いても2枚重ねになってしまいます。
|
18
26
|
|
19
27
|
###該当のソースコード
|
20
28
|
|
29
|
+
|
30
|
+
|
31
|
+
```
|
32
|
+
|
21
|
-
|
33
|
+
BufferedImage gazou1 = null; //Graphics gの場合の画像
|
22
34
|
|
23
35
|
|
24
36
|
|
25
|
-
|
37
|
+
|
26
38
|
|
27
|
-
|
39
|
+
/* Graphics gの場合 */
|
28
|
-
|
29
|
-
JLabel label,label2;
|
30
|
-
|
31
|
-
Thread th = null;
|
32
|
-
|
33
|
-
// BufferedImage gazou1 = null; //Graphics gの場合の画像
|
34
40
|
|
35
41
|
|
36
42
|
|
37
|
-
|
43
|
+
try{
|
38
44
|
|
39
|
-
int
|
45
|
+
gazou1 = ImageIO.read(new File("C:\\Users\\Owner\\Desktop\\gazou\\gazou1.png"));
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
public Mas(String title){
|
44
|
-
|
45
|
-
if(th == null){
|
46
|
-
|
47
|
-
th = new Thread(this);
|
48
|
-
|
49
|
-
th.start();
|
50
|
-
|
51
|
-
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
setUndecorated(true);
|
56
|
-
|
57
|
-
setBackground(new Color(0,0,0,0));
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
// GraphicsDevice device =
|
62
|
-
|
63
|
-
// GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
64
|
-
|
65
|
-
// device.setFullScreenWindow(this); //できない~~
|
66
|
-
|
67
|
-
this.setSize(1950,1200);
|
68
|
-
|
69
|
-
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
panel = new JPanel();
|
74
|
-
|
75
|
-
panel.setBackground(new Color(0,0,0,0));
|
76
|
-
|
77
|
-
panel.setLayout(null);
|
78
|
-
|
79
|
-
panel.setBounds(400,300,500,400);
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
panel2 = new JPanel();
|
84
|
-
|
85
|
-
panel2.setVisible(false);
|
86
|
-
|
87
|
-
panel2.setLayout(null);
|
88
|
-
|
89
|
-
panel2.setOpaque(false);
|
90
|
-
|
91
|
-
panel2.setBounds(0,0,getSize().width,getSize().height);
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
menubutton=new JButton("* 閉じる");
|
96
|
-
|
97
|
-
menubutton.setBounds(650,550,260,70);
|
98
|
-
|
99
|
-
menubutton.setForeground(new Color(250,120,150,130));
|
100
|
-
|
101
|
-
menubutton.setBorderPainted(false);
|
102
|
-
|
103
|
-
menubutton.setContentAreaFilled(false);
|
104
|
-
|
105
|
-
menubutton.setOpaque(false);
|
106
|
-
|
107
|
-
menubutton.setFont(new Font("MS ゴシック",Font.PLAIN,32));
|
108
|
-
|
109
|
-
panel.add(menubutton);
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
menubutton.addActionListener(this);
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
label = new JLabel();
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
label.setLayout(null);
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
label.setBounds(635,250,700,900);
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
ImageIcon menu = new ImageIcon("C:\\Users\\Owner\\Desktop\\gazou\\menu.png");
|
130
|
-
|
131
|
-
//↑ボタンの隣にある画像です。
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
label.setIcon(menu);
|
136
|
-
|
137
|
-
panel.add(label);
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
Container con = getContentPane();
|
142
|
-
|
143
|
-
con.add(panel);
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
//Graphics gの場合
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
// try{
|
152
|
-
|
153
|
-
// gazou1 = ImageIO.read(new File("C:\\Users\\Owner\\Desktop\\gazou\\gazou1.png"));
|
154
|
-
|
155
|
-
|
47
|
+
}catch(IOException ioe){}
|
156
|
-
|
157
|
-
}
|
158
48
|
|
159
49
|
|
160
50
|
|
51
|
+
|
52
|
+
|
161
|
-
/
|
53
|
+
/* ボタン操作 */
|
162
54
|
|
163
55
|
public void actionPerformed(ActionEvent e){
|
164
56
|
|
165
|
-
String bstring = e.getActionCommand();
|
57
|
+
String bstring = e.getActionCommand();
|
166
58
|
|
167
59
|
|
168
60
|
|
@@ -170,11 +62,7 @@
|
|
170
62
|
|
171
63
|
panel.setVisible(false);
|
172
64
|
|
173
|
-
gazouplay();
|
174
|
-
|
175
|
-
|
65
|
+
//gazouplay();
|
176
|
-
|
177
|
-
|
178
66
|
|
179
67
|
}
|
180
68
|
|
@@ -182,35 +70,11 @@
|
|
182
70
|
|
183
71
|
|
184
72
|
|
185
|
-
public void run(){
|
73
|
+
public void run(){}
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
while(th!=null){
|
190
|
-
|
191
|
-
try{
|
192
|
-
|
193
|
-
Thread.sleep(1000);
|
194
|
-
|
195
|
-
}catch(InterruptedException ex){};
|
196
|
-
|
197
|
-
if(ly>=450){
|
198
|
-
|
199
|
-
ly-=6;
|
200
|
-
|
201
|
-
}else{ ly+=6;}
|
202
74
|
|
203
75
|
|
204
76
|
|
205
|
-
repaint();
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
th = null;
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
//ImageIconの場合
|
77
|
+
//ImageIconの場合
|
214
78
|
|
215
79
|
public void gazouplay(){
|
216
80
|
|
@@ -223,10 +87,6 @@
|
|
223
87
|
|
224
88
|
|
225
89
|
label2 = new JLabel();
|
226
|
-
|
227
|
-
label2.setLayout(null);
|
228
|
-
|
229
|
-
label2.setBounds(lx, ly, 400, 500);
|
230
90
|
|
231
91
|
label2.setIcon(gazou1);
|
232
92
|
|
@@ -246,28 +106,24 @@
|
|
246
106
|
|
247
107
|
}
|
248
108
|
|
249
|
-
|
109
|
+
//paint? paintComponent? Graphics gの場合
|
250
110
|
|
251
111
|
|
252
112
|
|
253
|
-
|
113
|
+
public void paintComponent(Graphics g){
|
254
114
|
|
255
|
-
|
115
|
+
g.drawImage(gazou1,200,450,360,500,panel2);
|
256
116
|
|
257
|
-
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
}
|
258
122
|
|
259
123
|
|
260
124
|
|
261
|
-
public static void main(String[] args) {
|
262
125
|
|
263
|
-
Mas mas = new Mas("");
|
264
126
|
|
265
|
-
mas.setVisible(true);
|
266
127
|
|
267
|
-
|
268
128
|
|
269
|
-
|
129
|
+
```
|
270
|
-
|
271
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
272
|
-
|
273
|
-
非常に整っていないコードで大変恐縮ですが、お力添えよろしくお願いします。
|