回答編集履歴
3
普通のクラス
test
CHANGED
@@ -217,3 +217,177 @@
|
|
217
217
|
}
|
218
218
|
|
219
219
|
```
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
---
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
追記 普通のクラス
|
228
|
+
|
229
|
+
```Java
|
230
|
+
|
231
|
+
import java.awt.Color;
|
232
|
+
|
233
|
+
import java.awt.EventQueue;
|
234
|
+
|
235
|
+
import java.awt.Font;
|
236
|
+
|
237
|
+
import java.awt.FontMetrics;
|
238
|
+
|
239
|
+
import java.awt.GradientPaint;
|
240
|
+
|
241
|
+
import java.awt.Graphics;
|
242
|
+
|
243
|
+
import java.awt.Graphics2D;
|
244
|
+
|
245
|
+
import java.awt.Point;
|
246
|
+
|
247
|
+
import java.awt.Rectangle;
|
248
|
+
|
249
|
+
import java.awt.SystemColor;
|
250
|
+
|
251
|
+
import javax.swing.JFrame;
|
252
|
+
|
253
|
+
import javax.swing.JLabel;
|
254
|
+
|
255
|
+
import javax.swing.SwingUtilities;
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
// JFrameを継承してこのアプリ用にカスタマイズしたGUIクラスを作る
|
262
|
+
|
263
|
+
public class GUI extends JFrame {
|
264
|
+
|
265
|
+
public static void main(String[] args) {
|
266
|
+
|
267
|
+
EventQueue.invokeLater(new Runnable() { // ここも匿名クラスです
|
268
|
+
|
269
|
+
public void run() {
|
270
|
+
|
271
|
+
try {
|
272
|
+
|
273
|
+
GUI window = new GUI();
|
274
|
+
|
275
|
+
window.setVisible(true);
|
276
|
+
|
277
|
+
} catch (Exception e) {
|
278
|
+
|
279
|
+
e.printStackTrace();
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
});
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
public GUI() {
|
292
|
+
|
293
|
+
// このアプリ専用のいろんなカスタマイズ
|
294
|
+
|
295
|
+
setBackground(SystemColor.textHighlight);
|
296
|
+
|
297
|
+
setTitle("Nova Music Player");
|
298
|
+
|
299
|
+
setBounds(100, 100, 854, 450);
|
300
|
+
|
301
|
+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
// GradationLabelはJLabelの機能は当然全部持っているので、JLabel変数に入れても問題ない
|
306
|
+
|
307
|
+
JLabel lbl = new GradationLabel("Nova Music Player");
|
308
|
+
|
309
|
+
lbl.setToolTipText("");
|
310
|
+
|
311
|
+
lbl.setForeground(new Color(0, 255, 0));
|
312
|
+
|
313
|
+
lbl.setFont(new Font("源界明朝", Font.PLAIN, 80));
|
314
|
+
|
315
|
+
lbl.setBackground(Color.WHITE);
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
add(lbl);
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
// JLabelを継承してグラデーションのテキストを表示するラベルに改造
|
328
|
+
|
329
|
+
// でもほとんどの機能はJLabelに任せる
|
330
|
+
|
331
|
+
class GradationLabel extends JLabel {
|
332
|
+
|
333
|
+
public GradationLabel(String text) {
|
334
|
+
|
335
|
+
super(text);
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
// paintComponent(表示するところ)だけをグラデーションするロジックに置き換える
|
342
|
+
|
343
|
+
@Override
|
344
|
+
|
345
|
+
public void paintComponent(Graphics g) {
|
346
|
+
|
347
|
+
final Graphics2D g2 = (Graphics2D) g.create();
|
348
|
+
|
349
|
+
g2.setFont(getFont());
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
Rectangle viewR = new Rectangle();
|
354
|
+
|
355
|
+
viewR.width = getSize().width;
|
356
|
+
|
357
|
+
viewR.height = getSize().height;
|
358
|
+
|
359
|
+
Rectangle iconR = new Rectangle();
|
360
|
+
|
361
|
+
Rectangle textR = new Rectangle();
|
362
|
+
|
363
|
+
SwingUtilities.layoutCompoundLabel(this, g2.getFontMetrics(),
|
364
|
+
|
365
|
+
getText(), getIcon(),
|
366
|
+
|
367
|
+
getVerticalAlignment(), getHorizontalAlignment(),
|
368
|
+
|
369
|
+
getVerticalTextPosition(), getHorizontalTextPosition(),
|
370
|
+
|
371
|
+
viewR, iconR, textR, getIconTextGap());
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
FontMetrics fm = g2.getFontMetrics();
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
g2.setPaint(new GradientPaint(new Point(textR.x, textR.y), Color.WHITE,
|
380
|
+
|
381
|
+
new Point(textR.x, textR.y + textR.height), Color.PINK.darker()));
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
g2.drawString(getText(), textR.x, textR.y + fm.getMaxAscent());
|
386
|
+
|
387
|
+
g2.dispose();
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
```
|
2
全文
test
CHANGED
@@ -2,70 +2,218 @@
|
|
2
2
|
|
3
3
|
```Java
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
5
|
+
package MusicPlayer;
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
import java.awt.BorderLayout;
|
10
|
+
|
11
|
+
import java.awt.Color;
|
12
|
+
|
13
|
+
import java.awt.EventQueue;
|
14
|
+
|
15
|
+
import java.awt.Font;
|
16
|
+
|
17
|
+
import java.awt.FontMetrics;
|
18
|
+
|
19
|
+
import java.awt.GradientPaint;
|
20
|
+
|
21
|
+
import java.awt.Graphics;
|
22
|
+
|
23
|
+
import java.awt.Graphics2D;
|
24
|
+
|
25
|
+
import java.awt.Point;
|
26
|
+
|
27
|
+
import java.awt.Rectangle;
|
28
|
+
|
29
|
+
import java.awt.SystemColor;
|
30
|
+
|
31
|
+
import javax.swing.JFrame;
|
32
|
+
|
33
|
+
import javax.swing.JLabel;
|
34
|
+
|
35
|
+
import javax.swing.JMenu;
|
36
|
+
|
37
|
+
import javax.swing.JMenuBar;
|
38
|
+
|
39
|
+
import javax.swing.JMenuItem;
|
40
|
+
|
41
|
+
import javax.swing.SwingUtilities;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
public class GUI {
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
private JFrame frmNovaMusicPlayer;
|
50
|
+
|
51
|
+
private JLabel lblNovaMusicPlayer;
|
52
|
+
|
53
|
+
private JMenuBar menuBar;
|
54
|
+
|
55
|
+
private JMenu menu;
|
56
|
+
|
57
|
+
private JMenuItem menuItem;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
/**
|
62
|
+
|
63
|
+
* Launch the application.
|
64
|
+
|
65
|
+
*/
|
66
|
+
|
67
|
+
public static void main(String[] args) {
|
68
|
+
|
69
|
+
EventQueue.invokeLater(new Runnable() {
|
70
|
+
|
71
|
+
public void run() {
|
72
|
+
|
73
|
+
try {
|
74
|
+
|
75
|
+
GUI window = new GUI();
|
76
|
+
|
77
|
+
window.frmNovaMusicPlayer.setVisible(true);
|
78
|
+
|
79
|
+
} catch (Exception e) {
|
80
|
+
|
81
|
+
e.printStackTrace();
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
});
|
66
88
|
|
67
89
|
}
|
68
90
|
|
91
|
+
|
92
|
+
|
93
|
+
/**
|
94
|
+
|
95
|
+
* Create the application.
|
96
|
+
|
97
|
+
*/
|
98
|
+
|
99
|
+
public GUI() {
|
100
|
+
|
101
|
+
initialize();
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
/**
|
108
|
+
|
109
|
+
* Initialize the contents of the frame.
|
110
|
+
|
111
|
+
*/
|
112
|
+
|
113
|
+
private void initialize() {
|
114
|
+
|
115
|
+
frmNovaMusicPlayer = new JFrame();
|
116
|
+
|
117
|
+
frmNovaMusicPlayer.setBackground(SystemColor.textHighlight);
|
118
|
+
|
119
|
+
frmNovaMusicPlayer.setTitle("Nova Music Player");
|
120
|
+
|
121
|
+
frmNovaMusicPlayer.setBounds(100, 100, 854, 450);
|
122
|
+
|
123
|
+
frmNovaMusicPlayer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
124
|
+
|
125
|
+
frmNovaMusicPlayer.getContentPane().setLayout(new BorderLayout(0, 0));
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
menuBar = new JMenuBar();
|
130
|
+
|
131
|
+
menuBar.setBorderPainted(false);
|
132
|
+
|
133
|
+
menuBar.setBackground(new Color(255, 255, 255));
|
134
|
+
|
135
|
+
menuBar.setFont(new Font("Yu Gothic UI", Font.PLAIN, 12));
|
136
|
+
|
137
|
+
frmNovaMusicPlayer.getContentPane().add(menuBar, BorderLayout.NORTH);
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
menu = new JMenu("ファイル");
|
142
|
+
|
143
|
+
menuBar.add(menu);
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
JMenuItem menuItem_1 = new JMenuItem("音楽ファイルを開く");
|
148
|
+
|
149
|
+
menu.add(menuItem_1);
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
lblNovaMusicPlayer = new JLabel("Nova Music Player") {
|
154
|
+
|
155
|
+
@Override
|
156
|
+
|
157
|
+
public void paintComponent(Graphics g) {
|
158
|
+
|
159
|
+
final Graphics2D g2 = (Graphics2D) g.create();
|
160
|
+
|
161
|
+
g2.setFont(getFont());
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
Rectangle viewR = new Rectangle();
|
166
|
+
|
167
|
+
viewR.width = getSize().width;
|
168
|
+
|
169
|
+
viewR.height = getSize().height;
|
170
|
+
|
171
|
+
Rectangle iconR = new Rectangle();
|
172
|
+
|
173
|
+
Rectangle textR = new Rectangle();
|
174
|
+
|
175
|
+
SwingUtilities.layoutCompoundLabel(this, g2.getFontMetrics(),
|
176
|
+
|
177
|
+
getText(), getIcon(),
|
178
|
+
|
179
|
+
getVerticalAlignment(), getHorizontalAlignment(),
|
180
|
+
|
181
|
+
getVerticalTextPosition(), getHorizontalTextPosition(),
|
182
|
+
|
183
|
+
viewR, iconR, textR, getIconTextGap());
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
FontMetrics fm = g2.getFontMetrics();
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
g2.setPaint(new GradientPaint(new Point(textR.x, textR.y), Color.WHITE,
|
192
|
+
|
193
|
+
new Point(textR.x, textR.y + textR.height), Color.PINK.darker()));
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
g2.drawString(getText(), textR.x, textR.y + fm.getMaxAscent());
|
198
|
+
|
199
|
+
g2.dispose();
|
200
|
+
|
201
|
+
}
|
202
|
+
|
69
|
-
};
|
203
|
+
};
|
204
|
+
|
205
|
+
lblNovaMusicPlayer.setToolTipText("");
|
206
|
+
|
207
|
+
lblNovaMusicPlayer.setForeground(new Color(0, 255, 0));
|
208
|
+
|
209
|
+
lblNovaMusicPlayer.setFont(new Font("源界明朝", Font.PLAIN, 80));
|
210
|
+
|
211
|
+
lblNovaMusicPlayer.setBackground(Color.WHITE);
|
212
|
+
|
213
|
+
frmNovaMusicPlayer.getContentPane().add(lblNovaMusicPlayer);
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
}
|
70
218
|
|
71
219
|
```
|
1
絶対もっと簡単にできると思う^^;
test
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
1
|
+
絶対もっと簡単にできると思う^^;
|
2
|
-
|
3
|
-
|
4
2
|
|
5
3
|
```Java
|
6
4
|
|
@@ -12,23 +10,59 @@
|
|
12
10
|
|
13
11
|
final Graphics2D g2 = (Graphics2D) g.create();
|
14
12
|
|
15
|
-
g2.
|
13
|
+
// g2.fillRect(0, 0, getWidth(), getHeight());
|
16
14
|
|
17
|
-
|
15
|
+
g2.setFont(getFont());
|
18
16
|
|
19
|
-
Color.WHITE,
|
20
17
|
|
21
|
-
new Point(0, getHeight()),
|
22
18
|
|
23
|
-
|
19
|
+
Rectangle viewR = new Rectangle();
|
24
20
|
|
21
|
+
viewR.width = getSize().width;
|
22
|
+
|
23
|
+
viewR.height = getSize().height;
|
24
|
+
|
25
|
+
Rectangle iconR = new Rectangle();
|
26
|
+
|
27
|
+
Rectangle textR = new Rectangle();
|
28
|
+
|
29
|
+
SwingUtilities.layoutCompoundLabel(this, g2.getFontMetrics(),
|
30
|
+
|
31
|
+
getText(), getIcon(),
|
32
|
+
|
33
|
+
getVerticalAlignment(), getHorizontalAlignment(),
|
34
|
+
|
35
|
+
getVerticalTextPosition(), getHorizontalTextPosition(),
|
36
|
+
|
37
|
+
viewR, iconR, textR, getIconTextGap());
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
FontMetrics fm = g2.getFontMetrics();
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
// g2.setPaint(new GradientPaint(
|
46
|
+
|
47
|
+
// new Point(0, 0),
|
48
|
+
|
49
|
+
// Color.WHITE,
|
50
|
+
|
25
|
-
|
51
|
+
// new Point(0, getHeight()),
|
52
|
+
|
53
|
+
// Color.PINK.darker()));
|
54
|
+
|
55
|
+
g2.setPaint(new GradientPaint(new Point(textR.x, textR.y), Color.WHITE,
|
56
|
+
|
57
|
+
new Point(textR.x, textR.y + textR.height), Color.PINK.darker()));
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
g2.drawString(getText(), textR.x, textR.y + fm.getMaxAscent());
|
26
62
|
|
27
63
|
g2.dispose();
|
28
64
|
|
29
|
-
|
30
|
-
|
31
|
-
super.paintComponent(g);
|
65
|
+
// super.paintComponent(g);
|
32
66
|
|
33
67
|
}
|
34
68
|
|