質問編集履歴
6
エラーを、例外に変えました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
キーボードの、”n””m”を押すと音が鳴るサンプラーを作りたいのですが、
|
2
2
|
|
3
|
-
AudioFormatのあたりで、
|
3
|
+
AudioFormatのあたりで、例外が出ています。
|
4
|
-
|
4
|
+
|
5
|
-
|
5
|
+
例外:
|
6
6
|
|
7
7
|
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
|
8
8
|
|
9
9
|
調べてみると、"LineUnavailableException は、ラインが使用不可のため開けないことを示す例外です。この状況がもっともよく発生するのは、要求されたラインがすでにほかのアプリケーションによって使用されている場合です。"と、ありました。
|
10
10
|
|
11
|
+
ちなみに、他のアプリケーションは、すべて閉じました。
|
12
|
+
|
11
13
|
```java
|
12
14
|
|
13
15
|
AudioFormat frmt= new AudioFormat(44100,16,2,true,false);
|
5
音以外の、設定の変更。
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,12 +28,12 @@
|
|
28
28
|
|
29
29
|
import java.awt.BorderLayout;
|
30
30
|
|
31
|
-
import java.awt.event.
|
31
|
+
import java.awt.event.KeyEvent;
|
32
|
-
|
33
|
-
import java.awt.event.ActionListener;
|
34
32
|
|
35
33
|
import java.awt.event.KeyListener;
|
36
34
|
|
35
|
+
import java.awt.event.KeyListener;
|
36
|
+
|
37
37
|
import java.awt.event.KeyEvent;
|
38
38
|
|
39
39
|
import java.awt.Color;
|
@@ -94,17 +94,17 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
|
97
|
-
class Main extends JPanel
|
97
|
+
class Main extends JPanel {
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
-
byte[] wave_data = new byte[44100];
|
101
|
+
static byte[] wave_data = new byte[44100];
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
-
JSlider slider1 = new JSlider(0, 1000);
|
105
|
+
static JSlider slider1 = new JSlider(0, 1000);
|
106
|
-
|
106
|
+
|
107
|
-
JSlider slider2 = new JSlider(0, 1000);
|
107
|
+
static JSlider slider2 = new JSlider(0, 1000);
|
108
108
|
|
109
109
|
JPanel p1;
|
110
110
|
|
@@ -112,145 +112,217 @@
|
|
112
112
|
|
113
113
|
JPanel p3;
|
114
114
|
|
115
|
-
JPanel p4;
|
115
|
+
static JPanel p4;
|
116
116
|
|
117
117
|
JPanel p5;
|
118
118
|
|
119
|
-
JPanel p6;
|
119
|
+
JPanel p6, p7, p8;
|
120
|
-
|
120
|
+
|
121
|
-
JLabel label1;
|
121
|
+
static JLabel label1;
|
122
|
-
|
122
|
+
|
123
|
-
JLabel label2;
|
123
|
+
static JLabel label2;
|
124
|
-
|
124
|
+
|
125
|
-
JLabel label3;
|
125
|
+
static JLabel label3;
|
126
|
+
|
127
|
+
JButton button1, button2;
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
Main() {
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
slider1.setValue(100);
|
136
|
+
|
137
|
+
slider1.setFocusable(false);
|
138
|
+
|
139
|
+
slider1.addChangeListener(new Slider());
|
140
|
+
|
141
|
+
slider2.setValue(100);
|
142
|
+
|
143
|
+
slider2.setFocusable(false);
|
144
|
+
|
145
|
+
slider2.addChangeListener(new Slider());
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
p1 = new JPanel();
|
150
|
+
|
151
|
+
p1.add(slider1);
|
152
|
+
|
153
|
+
p1.add(slider2);
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
label1 = new JLabel();
|
158
|
+
|
159
|
+
label2 = new JLabel();
|
160
|
+
|
161
|
+
label1.setText(""+slider1.getValue());
|
162
|
+
|
163
|
+
label2.setText(""+slider2.getValue());
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
p3 = new JPanel();
|
168
|
+
|
169
|
+
p3.add(label1);
|
170
|
+
|
171
|
+
p3.add(label2);
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
p7 = new JPanel();
|
176
|
+
|
177
|
+
p8 = new JPanel();
|
178
|
+
|
179
|
+
Key key = new Key();
|
180
|
+
|
181
|
+
p7.addKeyListener(key);
|
182
|
+
|
183
|
+
p7.setFocusable(true);
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
p2 = new JPanel();
|
188
|
+
|
189
|
+
p2.setLayout(new BorderLayout());
|
190
|
+
|
191
|
+
p2.add(p1, BorderLayout.NORTH);
|
192
|
+
|
193
|
+
p2.add(p3, BorderLayout.CENTER);
|
194
|
+
|
195
|
+
p2.add(p7, BorderLayout.SOUTH);
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
label3 = new JLabel("");
|
200
|
+
|
201
|
+
p4 = new JPanel();
|
202
|
+
|
203
|
+
p4.setPreferredSize(new Dimension(600, 200));
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
p4.setLayout(new BorderLayout());
|
208
|
+
|
209
|
+
p4.add(label3, BorderLayout.NORTH);
|
210
|
+
|
211
|
+
p4.add(new Paint(), BorderLayout.SOUTH);
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
setLayout(new BorderLayout());
|
216
|
+
|
217
|
+
add(p2, BorderLayout.NORTH);
|
218
|
+
|
219
|
+
add(p4, BorderLayout.CENTER);
|
220
|
+
|
221
|
+
// p5.PpsetPreferredSize(new Dimension(600, 350));
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
class Key implements KeyListener {
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
int i;
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
public void keyPressed(KeyEvent e) {
|
236
|
+
|
237
|
+
Main.label3.setText(e.getKeyText(e.getKeyCode()));
|
238
|
+
|
239
|
+
if(e.getKeyCode() == KeyEvent.VK_N) {
|
240
|
+
|
241
|
+
new Sound(1);
|
242
|
+
|
243
|
+
}else if(e.getKeyCode() == KeyEvent.VK_M) {
|
244
|
+
|
245
|
+
new Sound(2);
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
Main.p4.add(new Paint());
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
public void keyReleased(KeyEvent e) {
|
256
|
+
|
257
|
+
// clip.drain();
|
258
|
+
|
259
|
+
// clip.close();
|
260
|
+
|
261
|
+
// clip.stop();
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
public void keyTyped(KeyEvent e) {}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
class Paint extends JPanel {
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
protected void paintComponent(Graphics g) {
|
276
|
+
|
277
|
+
super.paintComponent(g);
|
278
|
+
|
279
|
+
g.setColor(Color.RED);
|
280
|
+
|
281
|
+
for(int i = 0; i < (Main.wave_data.length/200-1); i++) {
|
282
|
+
|
283
|
+
g.drawLine(i*2,128-Main.wave_data[i*200],(i+1)*2,128-Main.wave_data[(i+1)*200]);
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
class Sound {
|
294
|
+
|
295
|
+
|
126
296
|
|
127
297
|
Clip clip;
|
128
298
|
|
129
|
-
|
299
|
+
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
300
|
+
|
135
|
-
|
301
|
+
Sound(int i) {
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
302
|
+
|
140
|
-
|
141
|
-
slider1.addChangeListener(this);
|
142
|
-
|
143
|
-
slider2.setValue(100);
|
144
|
-
|
145
|
-
slider2.addChangeListener(this);
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
p1 = new JPanel();
|
150
|
-
|
151
|
-
p1.add(slider1);
|
152
|
-
|
153
|
-
p1.add(slider2);
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
label1 = new JLabel();
|
158
|
-
|
159
|
-
label2 = new JLabel();
|
160
|
-
|
161
|
-
l
|
303
|
+
double l1 = i*Main.slider1.getValue()/44100.0;
|
162
|
-
|
304
|
+
|
163
|
-
l
|
305
|
+
double l2 = i*Main.slider2.getValue()/44100.0;
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
306
|
+
|
168
|
-
|
169
|
-
p3.add(label1);
|
170
|
-
|
171
|
-
p3.add(label2);
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
p2 = new JPanel();
|
176
|
-
|
177
|
-
// p4.setPreferredSize(new Dimension(600, 400));
|
178
|
-
|
179
|
-
|
307
|
+
for(int j=0;j<Main.wave_data.length;j++){
|
308
|
+
|
180
|
-
|
309
|
+
Main.wave_data[j]= (byte)(110*(Main.wave_data.length-(j+1))/Main.wave_data.length*Math.sin((j*l1)*Math.PI*2)
|
310
|
+
|
181
|
-
|
311
|
+
*Math.sin((j*l2)*Math.PI*2));
|
182
|
-
|
183
|
-
|
312
|
+
|
184
|
-
|
185
|
-
add(p2);
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
p4 = new JPanel();
|
190
|
-
|
191
|
-
// p4.setPreferredSize(new Dimension(600, 200));
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
p5 = new JPanel();
|
196
|
-
|
197
|
-
// p5.PpsetPreferredSize(new Dimension(600, 350));
|
198
|
-
|
199
|
-
p5.add(p3);
|
200
|
-
|
201
|
-
p5.add(p4);
|
202
|
-
|
203
|
-
add(p5);
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
label3 = new JLabel("");
|
208
|
-
|
209
|
-
add(label3);
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
setFocusable(true);
|
214
|
-
|
215
|
-
addKeyListener(this);
|
216
|
-
|
217
|
-
}
|
313
|
+
}
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
314
|
+
|
222
|
-
|
223
|
-
|
315
|
+
|
224
|
-
|
225
|
-
label2.setText(""+slider2.getValue());
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
void sound(int i) {
|
232
316
|
|
233
317
|
try{
|
234
318
|
|
235
|
-
double l1 = i*slider1.getValue()/44100.0;
|
236
|
-
|
237
|
-
double l2 = i*slider2.getValue()/44100.0;
|
238
|
-
|
239
|
-
for(int j=0;j<wave_data.length;j++){
|
240
|
-
|
241
|
-
wave_data[j]= (byte)(110*(wave_data.length-(j+1))/wave_data.length*Math.sin((j*l1)*Math.PI*2)
|
242
|
-
|
243
|
-
*Math.sin((j*l2)*Math.PI*2));
|
244
|
-
|
245
|
-
}
|
246
|
-
|
247
319
|
AudioFormat frmt= new AudioFormat(44100,16,2,true,false);
|
248
320
|
|
249
321
|
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
250
322
|
|
251
323
|
clip= (Clip)AudioSystem.getLine(info);
|
252
324
|
|
253
|
-
clip.open(frmt,wave_data,0,wave_data.length);
|
325
|
+
clip.open(frmt,Main.wave_data,0,Main.wave_data.length);
|
254
326
|
|
255
327
|
clip.start();
|
256
328
|
|
@@ -260,89 +332,21 @@
|
|
260
332
|
|
261
333
|
}
|
262
334
|
|
263
|
-
|
264
|
-
|
265
|
-
public void paintComponent(Graphics g) {
|
266
|
-
|
267
|
-
super.paintComponent(g);
|
268
|
-
|
269
|
-
g.setColor(Color.RED);
|
270
|
-
|
271
|
-
for(int i = 0; i < (wave_data.length/200-1); i++) {
|
272
|
-
|
273
|
-
g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
|
274
|
-
|
275
|
-
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
|
276
|
-
|
339
|
+
class Slider implements ChangeListener {
|
340
|
+
|
341
|
+
public void stateChanged(ChangeEvent e) {
|
342
|
+
|
343
|
+
Main.label1.setText(""+Main.slider1.getValue());
|
344
|
+
|
345
|
+
Main.label2.setText(""+Main.slider2.getValue());
|
346
|
+
|
277
|
-
|
347
|
+
}
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
348
|
+
|
282
|
-
|
283
|
-
if(e.getKeyCode() == KeyEvent.VK_N) {
|
284
|
-
|
285
|
-
sound(1);
|
286
|
-
|
287
|
-
label3.setText(e.getKeyText(e.getKeyCode()));
|
288
|
-
|
289
|
-
p4.repaint();
|
290
|
-
|
291
|
-
|
349
|
+
}
|
292
|
-
|
293
|
-
else if(e.getKeyCode() == KeyEvent.VK_M) {
|
294
|
-
|
295
|
-
sound(2);
|
296
|
-
|
297
|
-
label3.setText(e.getKeyText(e.getKeyCode()));
|
298
|
-
|
299
|
-
p4.repaint();
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
public void keyReleased(KeyEvent e) {
|
308
|
-
|
309
|
-
// clip.drain();
|
310
|
-
|
311
|
-
clip.close();
|
312
|
-
|
313
|
-
clip.stop();
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
public void keyTyped(KeyEvent e) {}
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
/*class FixString {
|
324
|
-
|
325
|
-
String string;
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
void setString(String string) {
|
330
|
-
|
331
|
-
this.string = string;
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
String getString() {
|
338
|
-
|
339
|
-
return string;
|
340
|
-
|
341
|
-
}
|
342
|
-
|
343
|
-
}*/
|
344
|
-
|
345
|
-
|
346
350
|
|
347
351
|
|
348
352
|
|
4
例外の、情報を更新。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,16 +1,290 @@
|
|
1
1
|
キーボードの、”n””m”を押すと音が鳴るサンプラーを作りたいのですが、
|
2
2
|
|
3
|
-
キーを押しても変化がありません。
|
4
|
-
|
5
|
-
|
3
|
+
AudioFormatのあたりで、エラーが出ています。
|
4
|
+
|
5
|
+
エラー:
|
6
|
+
|
7
|
+
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
|
8
|
+
|
9
|
+
調べてみると、"LineUnavailableException は、ラインが使用不可のため開けないことを示す例外です。この状況がもっともよく発生するのは、要求されたラインがすでにほかのアプリケーションによって使用されている場合です。"と、ありました。
|
6
10
|
|
7
11
|
```java
|
8
12
|
|
13
|
+
AudioFormat frmt= new AudioFormat(44100,16,2,true,false);
|
14
|
+
|
15
|
+
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
16
|
+
|
17
|
+
clip= (Clip)AudioSystem.getLine(info);
|
18
|
+
|
19
|
+
clip.open(frmt,wave_data,0,wave_data.length);
|
20
|
+
|
21
|
+
clip.start();
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
どなたか、ご指導くださる方、よろしくお願いいたします。
|
26
|
+
|
27
|
+
```java
|
28
|
+
|
29
|
+
import java.awt.BorderLayout;
|
30
|
+
|
31
|
+
import java.awt.event.ActionEvent;
|
32
|
+
|
33
|
+
import java.awt.event.ActionListener;
|
34
|
+
|
35
|
+
import java.awt.event.KeyListener;
|
36
|
+
|
37
|
+
import java.awt.event.KeyEvent;
|
38
|
+
|
39
|
+
import java.awt.Color;
|
40
|
+
|
41
|
+
import java.awt.Component;
|
42
|
+
|
43
|
+
import java.awt.Container;
|
44
|
+
|
45
|
+
import java.awt.Graphics;
|
46
|
+
|
47
|
+
import java.awt.Dimension;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
import java.lang.*;
|
52
|
+
|
53
|
+
import javax.swing.*;
|
54
|
+
|
55
|
+
import javax.swing.event.*;
|
56
|
+
|
57
|
+
import javax.sound.sampled.*;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public class SynthAkira extends JFrame {
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
public static void main(String[] args){
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
SynthAkira akira = new SynthAkira("Synth Akira");
|
70
|
+
|
71
|
+
akira.setVisible(true);
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
SynthAkira(String title){
|
78
|
+
|
79
|
+
setTitle(title);
|
80
|
+
|
81
|
+
setBounds(100, 100, 600, 600);
|
82
|
+
|
83
|
+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
Container contentPane = getContentPane();
|
88
|
+
|
89
|
+
contentPane.add(new Main(), BorderLayout.CENTER);
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
class Main extends JPanel implements ChangeListener, KeyListener {
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
byte[] wave_data = new byte[44100];
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
JSlider slider1 = new JSlider(0, 1000);
|
106
|
+
|
107
|
+
JSlider slider2 = new JSlider(0, 1000);
|
108
|
+
|
109
|
+
JPanel p1;
|
110
|
+
|
111
|
+
JPanel p2;
|
112
|
+
|
113
|
+
JPanel p3;
|
114
|
+
|
115
|
+
JPanel p4;
|
116
|
+
|
117
|
+
JPanel p5;
|
118
|
+
|
119
|
+
JPanel p6;
|
120
|
+
|
121
|
+
JLabel label1;
|
122
|
+
|
123
|
+
JLabel label2;
|
124
|
+
|
125
|
+
JLabel label3;
|
126
|
+
|
127
|
+
Clip clip;
|
128
|
+
|
129
|
+
Graphics g;
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
Main() {
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
slider1.setValue(100);
|
140
|
+
|
141
|
+
slider1.addChangeListener(this);
|
142
|
+
|
143
|
+
slider2.setValue(100);
|
144
|
+
|
145
|
+
slider2.addChangeListener(this);
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
p1 = new JPanel();
|
150
|
+
|
151
|
+
p1.add(slider1);
|
152
|
+
|
153
|
+
p1.add(slider2);
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
label1 = new JLabel();
|
158
|
+
|
159
|
+
label2 = new JLabel();
|
160
|
+
|
161
|
+
label1.setText(""+slider1.getValue());
|
162
|
+
|
163
|
+
label2.setText(""+slider2.getValue());
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
p3 = new JPanel();
|
168
|
+
|
169
|
+
p3.add(label1);
|
170
|
+
|
171
|
+
p3.add(label2);
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
p2 = new JPanel();
|
176
|
+
|
177
|
+
// p4.setPreferredSize(new Dimension(600, 400));
|
178
|
+
|
179
|
+
p2.setLayout(new BorderLayout());
|
180
|
+
|
181
|
+
p2.add(p1, BorderLayout.NORTH);
|
182
|
+
|
183
|
+
p2.add(p3, BorderLayout.CENTER);
|
184
|
+
|
185
|
+
add(p2);
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
p4 = new JPanel();
|
190
|
+
|
191
|
+
// p4.setPreferredSize(new Dimension(600, 200));
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
p5 = new JPanel();
|
196
|
+
|
197
|
+
// p5.PpsetPreferredSize(new Dimension(600, 350));
|
198
|
+
|
199
|
+
p5.add(p3);
|
200
|
+
|
201
|
+
p5.add(p4);
|
202
|
+
|
203
|
+
add(p5);
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
label3 = new JLabel("");
|
208
|
+
|
209
|
+
add(label3);
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
setFocusable(true);
|
214
|
+
|
215
|
+
addKeyListener(this);
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
public void stateChanged(ChangeEvent e) {
|
222
|
+
|
223
|
+
label1.setText(""+slider1.getValue());
|
224
|
+
|
225
|
+
label2.setText(""+slider2.getValue());
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
void sound(int i) {
|
232
|
+
|
233
|
+
try{
|
234
|
+
|
235
|
+
double l1 = i*slider1.getValue()/44100.0;
|
236
|
+
|
237
|
+
double l2 = i*slider2.getValue()/44100.0;
|
238
|
+
|
239
|
+
for(int j=0;j<wave_data.length;j++){
|
240
|
+
|
241
|
+
wave_data[j]= (byte)(110*(wave_data.length-(j+1))/wave_data.length*Math.sin((j*l1)*Math.PI*2)
|
242
|
+
|
243
|
+
*Math.sin((j*l2)*Math.PI*2));
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
AudioFormat frmt= new AudioFormat(44100,16,2,true,false);
|
248
|
+
|
249
|
+
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
250
|
+
|
251
|
+
clip= (Clip)AudioSystem.getLine(info);
|
252
|
+
|
253
|
+
clip.open(frmt,wave_data,0,wave_data.length);
|
254
|
+
|
255
|
+
clip.start();
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
catch(Exception e){e.printStackTrace(System.err);}
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
public void paintComponent(Graphics g) {
|
266
|
+
|
267
|
+
super.paintComponent(g);
|
268
|
+
|
269
|
+
g.setColor(Color.RED);
|
270
|
+
|
271
|
+
for(int i = 0; i < (wave_data.length/200-1); i++) {
|
272
|
+
|
273
|
+
g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
9
281
|
public void keyPressed(KeyEvent e) {
|
10
282
|
|
11
283
|
if(e.getKeyCode() == KeyEvent.VK_N) {
|
12
284
|
|
13
|
-
|
285
|
+
sound(1);
|
286
|
+
|
287
|
+
label3.setText(e.getKeyText(e.getKeyCode()));
|
14
288
|
|
15
289
|
p4.repaint();
|
16
290
|
|
@@ -20,356 +294,56 @@
|
|
20
294
|
|
21
295
|
sound(2);
|
22
296
|
|
297
|
+
label3.setText(e.getKeyText(e.getKeyCode()));
|
298
|
+
|
23
299
|
p4.repaint();
|
24
300
|
|
25
301
|
}
|
26
302
|
|
27
|
-
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
public void keyReleased(KeyEvent e) {
|
308
|
+
|
309
|
+
// clip.drain();
|
310
|
+
|
311
|
+
clip.close();
|
312
|
+
|
313
|
+
clip.stop();
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
public void keyTyped(KeyEvent e) {}
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
/*class FixString {
|
324
|
+
|
325
|
+
String string;
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
void setString(String string) {
|
330
|
+
|
331
|
+
this.string = string;
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
String getString() {
|
338
|
+
|
339
|
+
return string;
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
}*/
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
28
348
|
|
29
349
|
```
|
30
|
-
|
31
|
-
AudioFormatのあたりで、エラーが出ています。
|
32
|
-
|
33
|
-
エラー:
|
34
|
-
|
35
|
-
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
|
36
|
-
|
37
|
-
```java
|
38
|
-
|
39
|
-
AudioFormat frmt= new AudioFormat(44100,16,2,true,false);
|
40
|
-
|
41
|
-
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
42
|
-
|
43
|
-
clip= (Clip)AudioSystem.getLine(info);
|
44
|
-
|
45
|
-
clip.open(frmt,wave_data,0,wave_data.length);
|
46
|
-
|
47
|
-
clip.start();
|
48
|
-
|
49
|
-
```
|
50
|
-
|
51
|
-
どなたか、ご指導くださる方、よろしくお願いいたします。
|
52
|
-
|
53
|
-
```java
|
54
|
-
|
55
|
-
import java.awt.BorderLayout;
|
56
|
-
|
57
|
-
import java.awt.event.ActionEvent;
|
58
|
-
|
59
|
-
import java.awt.event.ActionListener;
|
60
|
-
|
61
|
-
import java.awt.event.KeyListener;
|
62
|
-
|
63
|
-
import java.awt.event.KeyEvent;
|
64
|
-
|
65
|
-
import java.awt.Color;
|
66
|
-
|
67
|
-
import java.awt.Component;
|
68
|
-
|
69
|
-
import java.awt.Container;
|
70
|
-
|
71
|
-
import java.awt.Graphics;
|
72
|
-
|
73
|
-
import java.awt.Dimension;
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
import java.lang.*;
|
78
|
-
|
79
|
-
import javax.swing.*;
|
80
|
-
|
81
|
-
import javax.swing.event.*;
|
82
|
-
|
83
|
-
import javax.sound.sampled.*;
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
public class SynthAkira extends JFrame {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
public static void main(String[] args){
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
SynthAkira akira = new SynthAkira("Synth Akira");
|
96
|
-
|
97
|
-
akira.setVisible(true);
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
SynthAkira(String title){
|
104
|
-
|
105
|
-
setTitle(title);
|
106
|
-
|
107
|
-
setBounds(100, 100, 600, 600);
|
108
|
-
|
109
|
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
Container contentPane = getContentPane();
|
114
|
-
|
115
|
-
contentPane.add(new Main(), BorderLayout.CENTER);
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
class Main extends JPanel implements ChangeListener, KeyListener {
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
byte[] wave_data = new byte[44100];
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
JSlider slider1 = new JSlider(0, 1000);
|
132
|
-
|
133
|
-
JSlider slider2 = new JSlider(0, 1000);
|
134
|
-
|
135
|
-
JPanel p1;
|
136
|
-
|
137
|
-
JPanel p2;
|
138
|
-
|
139
|
-
JPanel p3;
|
140
|
-
|
141
|
-
JPanel p4;
|
142
|
-
|
143
|
-
JPanel p5;
|
144
|
-
|
145
|
-
JPanel p6;
|
146
|
-
|
147
|
-
JLabel label1;
|
148
|
-
|
149
|
-
JLabel label2;
|
150
|
-
|
151
|
-
JLabel label3;
|
152
|
-
|
153
|
-
Clip clip;
|
154
|
-
|
155
|
-
Graphics g;
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
Main() {
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
slider1.setValue(100);
|
166
|
-
|
167
|
-
slider1.addChangeListener(this);
|
168
|
-
|
169
|
-
slider2.setValue(100);
|
170
|
-
|
171
|
-
slider2.addChangeListener(this);
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
p1 = new JPanel();
|
176
|
-
|
177
|
-
p1.add(slider1);
|
178
|
-
|
179
|
-
p1.add(slider2);
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
label1 = new JLabel();
|
184
|
-
|
185
|
-
label2 = new JLabel();
|
186
|
-
|
187
|
-
label1.setText(""+slider1.getValue());
|
188
|
-
|
189
|
-
label2.setText(""+slider2.getValue());
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
p3 = new JPanel();
|
194
|
-
|
195
|
-
p3.add(label1);
|
196
|
-
|
197
|
-
p3.add(label2);
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
p2 = new JPanel();
|
202
|
-
|
203
|
-
// p4.setPreferredSize(new Dimension(600, 400));
|
204
|
-
|
205
|
-
p2.setLayout(new BorderLayout());
|
206
|
-
|
207
|
-
p2.add(p1, BorderLayout.NORTH);
|
208
|
-
|
209
|
-
p2.add(p3, BorderLayout.CENTER);
|
210
|
-
|
211
|
-
add(p2);
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
p4 = new JPanel();
|
216
|
-
|
217
|
-
// p4.setPreferredSize(new Dimension(600, 200));
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
p5 = new JPanel();
|
222
|
-
|
223
|
-
// p5.PpsetPreferredSize(new Dimension(600, 350));
|
224
|
-
|
225
|
-
p5.add(p3);
|
226
|
-
|
227
|
-
p5.add(p4);
|
228
|
-
|
229
|
-
add(p5);
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
label3 = new JLabel("");
|
234
|
-
|
235
|
-
add(label3);
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
setFocusable(true);
|
240
|
-
|
241
|
-
addKeyListener(this);
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
public void stateChanged(ChangeEvent e) {
|
248
|
-
|
249
|
-
label1.setText(""+slider1.getValue());
|
250
|
-
|
251
|
-
label2.setText(""+slider2.getValue());
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
void sound(int i) {
|
258
|
-
|
259
|
-
try{
|
260
|
-
|
261
|
-
double l1 = i*slider1.getValue()/44100.0;
|
262
|
-
|
263
|
-
double l2 = i*slider2.getValue()/44100.0;
|
264
|
-
|
265
|
-
for(int j=0;j<wave_data.length;j++){
|
266
|
-
|
267
|
-
wave_data[j]= (byte)(110*(wave_data.length-(j+1))/wave_data.length*Math.sin((j*l1)*Math.PI*2)
|
268
|
-
|
269
|
-
*Math.sin((j*l2)*Math.PI*2));
|
270
|
-
|
271
|
-
}
|
272
|
-
|
273
|
-
AudioFormat frmt= new AudioFormat(44100,16,2,true,false);
|
274
|
-
|
275
|
-
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
276
|
-
|
277
|
-
clip= (Clip)AudioSystem.getLine(info);
|
278
|
-
|
279
|
-
clip.open(frmt,wave_data,0,wave_data.length);
|
280
|
-
|
281
|
-
clip.start();
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
catch(Exception e){e.printStackTrace(System.err);}
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
public void paintComponent(Graphics g) {
|
292
|
-
|
293
|
-
super.paintComponent(g);
|
294
|
-
|
295
|
-
g.setColor(Color.RED);
|
296
|
-
|
297
|
-
for(int i = 0; i < (wave_data.length/200-1); i++) {
|
298
|
-
|
299
|
-
g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
public void keyPressed(KeyEvent e) {
|
308
|
-
|
309
|
-
if(e.getKeyCode() == KeyEvent.VK_N) {
|
310
|
-
|
311
|
-
sound(1);
|
312
|
-
|
313
|
-
label3.setText(e.getKeyText(e.getKeyCode()));
|
314
|
-
|
315
|
-
p4.repaint();
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
else if(e.getKeyCode() == KeyEvent.VK_M) {
|
320
|
-
|
321
|
-
sound(2);
|
322
|
-
|
323
|
-
label3.setText(e.getKeyText(e.getKeyCode()));
|
324
|
-
|
325
|
-
p4.repaint();
|
326
|
-
|
327
|
-
}
|
328
|
-
|
329
|
-
}
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
public void keyReleased(KeyEvent e) {
|
334
|
-
|
335
|
-
// clip.drain();
|
336
|
-
|
337
|
-
clip.close();
|
338
|
-
|
339
|
-
clip.stop();
|
340
|
-
|
341
|
-
}
|
342
|
-
|
343
|
-
public void keyTyped(KeyEvent e) {}
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
/*class FixString {
|
350
|
-
|
351
|
-
String string;
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
void setString(String string) {
|
356
|
-
|
357
|
-
this.string = string;
|
358
|
-
|
359
|
-
}
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
String getString() {
|
364
|
-
|
365
|
-
return string;
|
366
|
-
|
367
|
-
}
|
368
|
-
|
369
|
-
}*/
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
```
|
3
AudioFormatのあたりで、エラーが出ているので、追記。
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,354 +28,348 @@
|
|
28
28
|
|
29
29
|
```
|
30
30
|
|
31
|
-
|
31
|
+
AudioFormatのあたりで、エラーが出ています。
|
32
|
+
|
33
|
+
エラー:
|
34
|
+
|
35
|
+
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
|
32
36
|
|
33
37
|
```java
|
34
38
|
|
39
|
+
AudioFormat frmt= new AudioFormat(44100,16,2,true,false);
|
40
|
+
|
41
|
+
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
42
|
+
|
43
|
+
clip= (Clip)AudioSystem.getLine(info);
|
44
|
+
|
45
|
+
clip.open(frmt,wave_data,0,wave_data.length);
|
46
|
+
|
47
|
+
clip.start();
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
どなたか、ご指導くださる方、よろしくお願いいたします。
|
52
|
+
|
53
|
+
```java
|
54
|
+
|
55
|
+
import java.awt.BorderLayout;
|
56
|
+
|
57
|
+
import java.awt.event.ActionEvent;
|
58
|
+
|
59
|
+
import java.awt.event.ActionListener;
|
60
|
+
|
61
|
+
import java.awt.event.KeyListener;
|
62
|
+
|
63
|
+
import java.awt.event.KeyEvent;
|
64
|
+
|
65
|
+
import java.awt.Color;
|
66
|
+
|
67
|
+
import java.awt.Component;
|
68
|
+
|
69
|
+
import java.awt.Container;
|
70
|
+
|
71
|
+
import java.awt.Graphics;
|
72
|
+
|
73
|
+
import java.awt.Dimension;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
import java.lang.*;
|
78
|
+
|
79
|
+
import javax.swing.*;
|
80
|
+
|
81
|
+
import javax.swing.event.*;
|
82
|
+
|
83
|
+
import javax.sound.sampled.*;
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
public class SynthAkira extends JFrame {
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
public static void main(String[] args){
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
SynthAkira akira = new SynthAkira("Synth Akira");
|
96
|
+
|
97
|
+
akira.setVisible(true);
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
SynthAkira(String title){
|
104
|
+
|
105
|
+
setTitle(title);
|
106
|
+
|
107
|
+
setBounds(100, 100, 600, 600);
|
108
|
+
|
109
|
+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
Container contentPane = getContentPane();
|
114
|
+
|
115
|
+
contentPane.add(new Main(), BorderLayout.CENTER);
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
class Main extends JPanel implements ChangeListener, KeyListener {
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
byte[] wave_data = new byte[44100];
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
JSlider slider1 = new JSlider(0, 1000);
|
132
|
+
|
133
|
+
JSlider slider2 = new JSlider(0, 1000);
|
134
|
+
|
135
|
+
JPanel p1;
|
136
|
+
|
137
|
+
JPanel p2;
|
138
|
+
|
139
|
+
JPanel p3;
|
140
|
+
|
141
|
+
JPanel p4;
|
142
|
+
|
143
|
+
JPanel p5;
|
144
|
+
|
145
|
+
JPanel p6;
|
146
|
+
|
147
|
+
JLabel label1;
|
148
|
+
|
149
|
+
JLabel label2;
|
150
|
+
|
151
|
+
JLabel label3;
|
152
|
+
|
153
|
+
Clip clip;
|
154
|
+
|
155
|
+
Graphics g;
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
Main() {
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
slider1.setValue(100);
|
166
|
+
|
167
|
+
slider1.addChangeListener(this);
|
168
|
+
|
169
|
+
slider2.setValue(100);
|
170
|
+
|
171
|
+
slider2.addChangeListener(this);
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
p1 = new JPanel();
|
176
|
+
|
177
|
+
p1.add(slider1);
|
178
|
+
|
179
|
+
p1.add(slider2);
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
label1 = new JLabel();
|
184
|
+
|
185
|
+
label2 = new JLabel();
|
186
|
+
|
187
|
+
label1.setText(""+slider1.getValue());
|
188
|
+
|
189
|
+
label2.setText(""+slider2.getValue());
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
p3 = new JPanel();
|
194
|
+
|
195
|
+
p3.add(label1);
|
196
|
+
|
197
|
+
p3.add(label2);
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
p2 = new JPanel();
|
202
|
+
|
203
|
+
// p4.setPreferredSize(new Dimension(600, 400));
|
204
|
+
|
205
|
+
p2.setLayout(new BorderLayout());
|
206
|
+
|
207
|
+
p2.add(p1, BorderLayout.NORTH);
|
208
|
+
|
209
|
+
p2.add(p3, BorderLayout.CENTER);
|
210
|
+
|
211
|
+
add(p2);
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
p4 = new JPanel();
|
216
|
+
|
217
|
+
// p4.setPreferredSize(new Dimension(600, 200));
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
p5 = new JPanel();
|
222
|
+
|
223
|
+
// p5.PpsetPreferredSize(new Dimension(600, 350));
|
224
|
+
|
225
|
+
p5.add(p3);
|
226
|
+
|
227
|
+
p5.add(p4);
|
228
|
+
|
229
|
+
add(p5);
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
label3 = new JLabel("");
|
234
|
+
|
235
|
+
add(label3);
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
setFocusable(true);
|
240
|
+
|
241
|
+
addKeyListener(this);
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
public void stateChanged(ChangeEvent e) {
|
248
|
+
|
249
|
+
label1.setText(""+slider1.getValue());
|
250
|
+
|
251
|
+
label2.setText(""+slider2.getValue());
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
void sound(int i) {
|
258
|
+
|
259
|
+
try{
|
260
|
+
|
261
|
+
double l1 = i*slider1.getValue()/44100.0;
|
262
|
+
|
263
|
+
double l2 = i*slider2.getValue()/44100.0;
|
264
|
+
|
265
|
+
for(int j=0;j<wave_data.length;j++){
|
266
|
+
|
267
|
+
wave_data[j]= (byte)(110*(wave_data.length-(j+1))/wave_data.length*Math.sin((j*l1)*Math.PI*2)
|
268
|
+
|
269
|
+
*Math.sin((j*l2)*Math.PI*2));
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
AudioFormat frmt= new AudioFormat(44100,16,2,true,false);
|
274
|
+
|
275
|
+
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
276
|
+
|
277
|
+
clip= (Clip)AudioSystem.getLine(info);
|
278
|
+
|
279
|
+
clip.open(frmt,wave_data,0,wave_data.length);
|
280
|
+
|
281
|
+
clip.start();
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
catch(Exception e){e.printStackTrace(System.err);}
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
public void paintComponent(Graphics g) {
|
292
|
+
|
293
|
+
super.paintComponent(g);
|
294
|
+
|
295
|
+
g.setColor(Color.RED);
|
296
|
+
|
297
|
+
for(int i = 0; i < (wave_data.length/200-1); i++) {
|
298
|
+
|
299
|
+
g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
|
35
307
|
public void keyPressed(KeyEvent e) {
|
36
308
|
|
37
|
-
|
309
|
+
if(e.getKeyCode() == KeyEvent.VK_N) {
|
38
|
-
|
310
|
+
|
39
|
-
|
311
|
+
sound(1);
|
40
|
-
|
312
|
+
|
41
|
-
label3.setText(
|
313
|
+
label3.setText(e.getKeyText(e.getKeyCode()));
|
42
|
-
|
314
|
+
|
43
|
-
|
315
|
+
p4.repaint();
|
44
|
-
|
45
|
-
|
316
|
+
|
46
|
-
|
47
|
-
// else if(e.getKeyCode() == KeyEvent.VK_M) {
|
48
|
-
|
49
|
-
// sound(2);
|
50
|
-
|
51
|
-
// label3.setText("m");
|
52
|
-
|
53
|
-
// p4.repaint();
|
54
|
-
|
55
|
-
// }
|
56
|
-
|
57
|
-
// else {}
|
58
|
-
|
59
|
-
}
|
317
|
+
}
|
318
|
+
|
60
|
-
|
319
|
+
else if(e.getKeyCode() == KeyEvent.VK_M) {
|
320
|
+
|
61
|
-
|
321
|
+
sound(2);
|
322
|
+
|
62
|
-
|
323
|
+
label3.setText(e.getKeyText(e.getKeyCode()));
|
324
|
+
|
325
|
+
p4.repaint();
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
|
332
|
+
|
63
|
-
public void keyReleased(KeyEvent e) {
|
333
|
+
public void keyReleased(KeyEvent e) {
|
334
|
+
|
335
|
+
// clip.drain();
|
336
|
+
|
337
|
+
clip.close();
|
338
|
+
|
339
|
+
clip.stop();
|
340
|
+
|
341
|
+
}
|
64
342
|
|
65
343
|
public void keyTyped(KeyEvent e) {}
|
66
344
|
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
/*class FixString {
|
350
|
+
|
351
|
+
String string;
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
void setString(String string) {
|
356
|
+
|
357
|
+
this.string = string;
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
String getString() {
|
364
|
+
|
365
|
+
return string;
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
}*/
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
67
375
|
```
|
68
|
-
|
69
|
-
どなたか、ご指導くださる方、よろしくお願いいたします。
|
70
|
-
|
71
|
-
```java
|
72
|
-
|
73
|
-
import java.awt.BorderLayout;
|
74
|
-
|
75
|
-
import java.awt.event.ActionEvent;
|
76
|
-
|
77
|
-
import java.awt.event.ActionListener;
|
78
|
-
|
79
|
-
import java.awt.event.KeyListener;
|
80
|
-
|
81
|
-
import java.awt.event.KeyEvent;
|
82
|
-
|
83
|
-
import java.awt.Color;
|
84
|
-
|
85
|
-
import java.awt.Component;
|
86
|
-
|
87
|
-
import java.awt.Container;
|
88
|
-
|
89
|
-
import java.awt.Graphics;
|
90
|
-
|
91
|
-
import java.awt.Dimension;
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
import java.lang.*;
|
96
|
-
|
97
|
-
import javax.swing.*;
|
98
|
-
|
99
|
-
import javax.swing.event.*;
|
100
|
-
|
101
|
-
import javax.sound.sampled.*;
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
public class SynthAkira extends JFrame {
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
public static void main(String[] args){
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
SynthAkira akira = new SynthAkira("Synth Akira");
|
114
|
-
|
115
|
-
akira.setVisible(true);
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
SynthAkira(String title){
|
122
|
-
|
123
|
-
setTitle(title);
|
124
|
-
|
125
|
-
setBounds(100, 100, 600, 600);
|
126
|
-
|
127
|
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
Container contentPane = getContentPane();
|
132
|
-
|
133
|
-
contentPane.add(new Main(), BorderLayout.CENTER);
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
class Main extends JPanel implements ChangeListener, KeyListener {
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
byte[] wave_data = new byte[44100];
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
JSlider slider1 = new JSlider(0, 1000);
|
150
|
-
|
151
|
-
JSlider slider2 = new JSlider(0, 1000);
|
152
|
-
|
153
|
-
JPanel p1;
|
154
|
-
|
155
|
-
JPanel p2;
|
156
|
-
|
157
|
-
JPanel p3;
|
158
|
-
|
159
|
-
JPanel p4;
|
160
|
-
|
161
|
-
JPanel p5;
|
162
|
-
|
163
|
-
JPanel p6;
|
164
|
-
|
165
|
-
JLabel label1;
|
166
|
-
|
167
|
-
JLabel label2;
|
168
|
-
|
169
|
-
JLabel label3;
|
170
|
-
|
171
|
-
Graphics g;
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
Main() {
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
slider1.setValue(100);
|
182
|
-
|
183
|
-
slider1.addChangeListener(this);
|
184
|
-
|
185
|
-
slider2.setValue(100);
|
186
|
-
|
187
|
-
slider2.addChangeListener(this);
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
p1 = new JPanel();
|
192
|
-
|
193
|
-
p1.add(slider1);
|
194
|
-
|
195
|
-
p1.add(slider2);
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
label1 = new JLabel();
|
200
|
-
|
201
|
-
label2 = new JLabel();
|
202
|
-
|
203
|
-
label1.setText("値:"+slider1.getValue());
|
204
|
-
|
205
|
-
label2.setText("値:"+slider2.getValue());
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
p3 = new JPanel();
|
210
|
-
|
211
|
-
p3.add(label1);
|
212
|
-
|
213
|
-
p3.add(label2);
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
p2 = new JPanel();
|
218
|
-
|
219
|
-
// p4.setPreferredSize(new Dimension(600, 400));
|
220
|
-
|
221
|
-
p2.setLayout(new BorderLayout());
|
222
|
-
|
223
|
-
p2.add(p1, BorderLayout.NORTH);
|
224
|
-
|
225
|
-
p2.add(p3, BorderLayout.CENTER);
|
226
|
-
|
227
|
-
add(p2);
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
p4 = new JPanel();
|
232
|
-
|
233
|
-
// p4.setPreferredSize(new Dimension(600, 200));
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
p5 = new JPanel();
|
238
|
-
|
239
|
-
// p5.setPreferredSize(new Dimension(600, 350));
|
240
|
-
|
241
|
-
p5.add(p3);
|
242
|
-
|
243
|
-
p5.add(p4);
|
244
|
-
|
245
|
-
add(p5);
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
label3 = new JLabel("");
|
250
|
-
|
251
|
-
add(label3);
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
addKeyListener(this);
|
256
|
-
|
257
|
-
}
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
public void stateChanged(ChangeEvent e) {
|
262
|
-
|
263
|
-
label1.setText("値:"+slider1.getValue());
|
264
|
-
|
265
|
-
label2.setText("値:"+slider2.getValue());
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
void sound(int i) {
|
272
|
-
|
273
|
-
try{
|
274
|
-
|
275
|
-
double l1 = i*slider1.getValue()/44100.0;
|
276
|
-
|
277
|
-
double l2 = i*slider2.getValue()/44100.0;
|
278
|
-
|
279
|
-
for(int j=0;j<wave_data.length;j++){
|
280
|
-
|
281
|
-
wave_data[j]= (byte)(110*(wave_data.length-(j+1))/wave_data.length*Math.sin((j*l1)*Math.PI*2)
|
282
|
-
|
283
|
-
*Math.sin((j*l2)*Math.PI*2));
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
AudioFormat frmt= new AudioFormat(44100,8,1,true,false);
|
288
|
-
|
289
|
-
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
290
|
-
|
291
|
-
Clip clip= (Clip)AudioSystem.getLine(info);
|
292
|
-
|
293
|
-
clip.open(frmt,wave_data,0,wave_data.length);
|
294
|
-
|
295
|
-
clip.start();
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
catch(Exception e){e.printStackTrace(System.err);}
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
public void paintComponent(Graphics g) {
|
306
|
-
|
307
|
-
super.paintComponent(g);
|
308
|
-
|
309
|
-
g.setColor(Color.RED);
|
310
|
-
|
311
|
-
for(int i = 0; i < (wave_data.length/200-1); i++) {
|
312
|
-
|
313
|
-
g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
public void keyPressed(KeyEvent e) {
|
322
|
-
|
323
|
-
// if(e.getKeyCode() == KeyEvent.VK_N) {
|
324
|
-
|
325
|
-
// sound(1);
|
326
|
-
|
327
|
-
label3.setText("hello!");
|
328
|
-
|
329
|
-
// p4.repaint();
|
330
|
-
|
331
|
-
// }
|
332
|
-
|
333
|
-
// else if(e.getKeyCode() == KeyEvent.VK_M) {
|
334
|
-
|
335
|
-
// sound(2);
|
336
|
-
|
337
|
-
// label3.setText("m");
|
338
|
-
|
339
|
-
// p4.repaint();
|
340
|
-
|
341
|
-
// }
|
342
|
-
|
343
|
-
// else {}
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
public void keyReleased(KeyEvent e) {}
|
350
|
-
|
351
|
-
public void keyTyped(KeyEvent e) {}
|
352
|
-
|
353
|
-
}
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
/*class FixString {
|
358
|
-
|
359
|
-
String string;
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
void setString(String string) {
|
364
|
-
|
365
|
-
this.string = string;
|
366
|
-
|
367
|
-
}
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
String getString() {
|
372
|
-
|
373
|
-
return string;
|
374
|
-
|
375
|
-
}
|
376
|
-
|
377
|
-
}*/
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
```
|
2
回答に関する変更。
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,15 +28,41 @@
|
|
28
28
|
|
29
29
|
```
|
30
30
|
|
31
|
-
|
31
|
+
KeyListenerのオーバーライドの部分を、下記のように変えても、変わりませんでした。
|
32
32
|
|
33
33
|
```java
|
34
34
|
|
35
|
-
p6 = new JPanel();
|
36
|
-
|
37
|
-
|
35
|
+
public void keyPressed(KeyEvent e) {
|
36
|
+
|
38
|
-
|
37
|
+
// if(e.getKeyCode() == KeyEvent.VK_N) {
|
38
|
+
|
39
|
-
|
39
|
+
// sound(1);
|
40
|
+
|
41
|
+
label3.setText("hello!");
|
42
|
+
|
43
|
+
// p4.repaint();
|
44
|
+
|
45
|
+
// }
|
46
|
+
|
47
|
+
// else if(e.getKeyCode() == KeyEvent.VK_M) {
|
48
|
+
|
49
|
+
// sound(2);
|
50
|
+
|
51
|
+
// label3.setText("m");
|
52
|
+
|
53
|
+
// p4.repaint();
|
54
|
+
|
55
|
+
// }
|
56
|
+
|
57
|
+
// else {}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
public void keyReleased(KeyEvent e) {}
|
64
|
+
|
65
|
+
public void keyTyped(KeyEvent e) {}
|
40
66
|
|
41
67
|
```
|
42
68
|
|
@@ -44,10 +70,6 @@
|
|
44
70
|
|
45
71
|
```java
|
46
72
|
|
47
|
-
package net.ddns.fantasia;
|
48
|
-
|
49
|
-
|
50
|
-
|
51
73
|
import java.awt.BorderLayout;
|
52
74
|
|
53
75
|
import java.awt.event.ActionEvent;
|
@@ -144,6 +166,8 @@
|
|
144
166
|
|
145
167
|
JLabel label2;
|
146
168
|
|
169
|
+
JLabel label3;
|
170
|
+
|
147
171
|
Graphics g;
|
148
172
|
|
149
173
|
|
@@ -172,91 +196,151 @@
|
|
172
196
|
|
173
197
|
|
174
198
|
|
199
|
+
label1 = new JLabel();
|
200
|
+
|
201
|
+
label2 = new JLabel();
|
202
|
+
|
203
|
+
label1.setText("値:"+slider1.getValue());
|
204
|
+
|
205
|
+
label2.setText("値:"+slider2.getValue());
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
p3 = new JPanel();
|
210
|
+
|
211
|
+
p3.add(label1);
|
212
|
+
|
213
|
+
p3.add(label2);
|
214
|
+
|
215
|
+
|
216
|
+
|
175
217
|
p2 = new JPanel();
|
176
218
|
|
177
219
|
// p4.setPreferredSize(new Dimension(600, 400));
|
178
220
|
|
179
221
|
p2.setLayout(new BorderLayout());
|
180
222
|
|
223
|
+
p2.add(p1, BorderLayout.NORTH);
|
224
|
+
|
181
|
-
p2.add(p
|
225
|
+
p2.add(p3, BorderLayout.CENTER);
|
182
|
-
|
183
|
-
|
184
|
-
|
226
|
+
|
185
|
-
|
227
|
+
add(p2);
|
186
|
-
|
187
|
-
|
188
|
-
|
228
|
+
|
229
|
+
|
230
|
+
|
189
|
-
|
231
|
+
p4 = new JPanel();
|
232
|
+
|
190
|
-
|
233
|
+
// p4.setPreferredSize(new Dimension(600, 200));
|
234
|
+
|
235
|
+
|
236
|
+
|
191
|
-
|
237
|
+
p5 = new JPanel();
|
238
|
+
|
239
|
+
// p5.setPreferredSize(new Dimension(600, 350));
|
240
|
+
|
241
|
+
p5.add(p3);
|
242
|
+
|
243
|
+
p5.add(p4);
|
244
|
+
|
245
|
+
add(p5);
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
label3 = new JLabel("");
|
250
|
+
|
251
|
+
add(label3);
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
addKeyListener(this);
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
public void stateChanged(ChangeEvent e) {
|
192
262
|
|
193
263
|
label1.setText("値:"+slider1.getValue());
|
194
264
|
|
195
265
|
label2.setText("値:"+slider2.getValue());
|
196
266
|
|
197
|
-
|
198
|
-
|
199
|
-
p3 = new JPanel();
|
200
|
-
|
201
|
-
p3.add(label1);
|
202
|
-
|
203
|
-
p3.add(label2);
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
p4 = new JPanel();
|
208
|
-
|
209
|
-
// p4.setPreferredSize(new Dimension(600, 200));
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
p5 = new JPanel();
|
214
|
-
|
215
|
-
// p5.setPreferredSize(new Dimension(600, 350));
|
216
|
-
|
217
|
-
p5.add(p3);
|
218
|
-
|
219
|
-
p5.add(p4);
|
220
|
-
|
221
|
-
add(p5);
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
p6 = new JPanel();
|
226
|
-
|
227
|
-
p6.addKeyListener(this);
|
228
|
-
|
229
|
-
}
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
230
|
-
|
271
|
+
void sound(int i) {
|
272
|
+
|
231
|
-
|
273
|
+
try{
|
274
|
+
|
232
|
-
|
275
|
+
double l1 = i*slider1.getValue()/44100.0;
|
276
|
+
|
277
|
+
double l2 = i*slider2.getValue()/44100.0;
|
278
|
+
|
233
|
-
|
279
|
+
for(int j=0;j<wave_data.length;j++){
|
280
|
+
|
234
|
-
|
281
|
+
wave_data[j]= (byte)(110*(wave_data.length-(j+1))/wave_data.length*Math.sin((j*l1)*Math.PI*2)
|
282
|
+
|
235
|
-
|
283
|
+
*Math.sin((j*l2)*Math.PI*2));
|
236
|
-
|
237
|
-
|
284
|
+
|
238
|
-
|
239
|
-
}
|
285
|
+
}
|
286
|
+
|
287
|
+
AudioFormat frmt= new AudioFormat(44100,8,1,true,false);
|
288
|
+
|
289
|
+
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
290
|
+
|
291
|
+
Clip clip= (Clip)AudioSystem.getLine(info);
|
292
|
+
|
293
|
+
clip.open(frmt,wave_data,0,wave_data.length);
|
294
|
+
|
295
|
+
clip.start();
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
catch(Exception e){e.printStackTrace(System.err);}
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
public void paintComponent(Graphics g) {
|
306
|
+
|
307
|
+
super.paintComponent(g);
|
308
|
+
|
309
|
+
g.setColor(Color.RED);
|
310
|
+
|
311
|
+
for(int i = 0; i < (wave_data.length/200-1); i++) {
|
312
|
+
|
313
|
+
g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
}
|
240
318
|
|
241
319
|
|
242
320
|
|
243
321
|
public void keyPressed(KeyEvent e) {
|
244
322
|
|
245
|
-
if(e.getKeyCode() == KeyEvent.VK_N) {
|
323
|
+
// if(e.getKeyCode() == KeyEvent.VK_N) {
|
246
|
-
|
324
|
+
|
247
|
-
|
325
|
+
// sound(1);
|
326
|
+
|
248
|
-
|
327
|
+
label3.setText("hello!");
|
328
|
+
|
249
|
-
p4.repaint();
|
329
|
+
// p4.repaint();
|
250
|
-
|
330
|
+
|
251
|
-
}
|
331
|
+
// }
|
252
|
-
|
332
|
+
|
253
|
-
else if(e.getKeyCode() == KeyEvent.VK_M) {
|
333
|
+
// else if(e.getKeyCode() == KeyEvent.VK_M) {
|
254
|
-
|
334
|
+
|
255
|
-
sound(2);
|
335
|
+
// sound(2);
|
336
|
+
|
256
|
-
|
337
|
+
// label3.setText("m");
|
338
|
+
|
257
|
-
p4.repaint();
|
339
|
+
// p4.repaint();
|
258
|
-
|
340
|
+
|
259
|
-
}
|
341
|
+
// }
|
342
|
+
|
343
|
+
// else {}
|
260
344
|
|
261
345
|
}
|
262
346
|
|
@@ -264,62 +348,34 @@
|
|
264
348
|
|
265
349
|
public void keyReleased(KeyEvent e) {}
|
266
350
|
|
267
|
-
|
268
|
-
|
269
|
-
|
351
|
+
public void keyTyped(KeyEvent e) {}
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
void sound(int i) {
|
274
|
-
|
275
|
-
try{
|
276
|
-
|
277
|
-
double l1 = i*slider1.getValue()/44100.0;
|
278
|
-
|
279
|
-
double l2 = i*slider2.getValue()/44100.0;
|
280
|
-
|
281
|
-
for(int j=0;j<wave_data.length;j++){
|
282
|
-
|
283
|
-
wave_data[j]= (byte)(110*(wave_data.length-(j+1))/wave_data.length*Math.sin((j*l1)*Math.PI*2)
|
284
|
-
|
285
|
-
*Math.sin((j*l2)*Math.PI*2));
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
AudioFormat frmt= new AudioFormat(44100,8,1,true,false);
|
290
|
-
|
291
|
-
DataLine.Info info= new DataLine.Info(Clip.class,frmt);
|
292
|
-
|
293
|
-
Clip clip= (Clip)AudioSystem.getLine(info);
|
294
|
-
|
295
|
-
clip.open(frmt,wave_data,0,wave_data.length);
|
296
|
-
|
297
|
-
clip.start();
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
catch(Exception e){e.printStackTrace(System.err);}
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
public void paintComponent(Graphics g) {
|
308
|
-
|
309
|
-
super.paintComponent(g);
|
310
|
-
|
311
|
-
g.setColor(Color.RED);
|
312
|
-
|
313
|
-
for(int i = 0; i < (wave_data.length/200-1); i++) {
|
314
|
-
|
315
|
-
g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
}
|
320
352
|
|
321
353
|
}
|
322
354
|
|
323
355
|
|
324
356
|
|
357
|
+
/*class FixString {
|
358
|
+
|
359
|
+
String string;
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
void setString(String string) {
|
364
|
+
|
365
|
+
this.string = string;
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
String getString() {
|
372
|
+
|
373
|
+
return string;
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
}*/
|
378
|
+
|
379
|
+
|
380
|
+
|
325
381
|
```
|
1
コードを、追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,10 +28,26 @@
|
|
28
28
|
|
29
29
|
```
|
30
30
|
|
31
|
+
ご回答があったので、下記を追加いたしましたが、動きません。
|
32
|
+
|
33
|
+
```java
|
34
|
+
|
35
|
+
p6 = new JPanel();
|
36
|
+
|
37
|
+
p6.addKeyListener(this);
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
```
|
42
|
+
|
31
43
|
どなたか、ご指導くださる方、よろしくお願いいたします。
|
32
44
|
|
33
45
|
```java
|
34
46
|
|
47
|
+
package net.ddns.fantasia;
|
48
|
+
|
49
|
+
|
50
|
+
|
35
51
|
import java.awt.BorderLayout;
|
36
52
|
|
37
53
|
import java.awt.event.ActionEvent;
|
@@ -122,6 +138,8 @@
|
|
122
138
|
|
123
139
|
JPanel p5;
|
124
140
|
|
141
|
+
JPanel p6;
|
142
|
+
|
125
143
|
JLabel label1;
|
126
144
|
|
127
145
|
JLabel label2;
|
@@ -202,6 +220,12 @@
|
|
202
220
|
|
203
221
|
add(p5);
|
204
222
|
|
223
|
+
|
224
|
+
|
225
|
+
p6 = new JPanel();
|
226
|
+
|
227
|
+
p6.addKeyListener(this);
|
228
|
+
|
205
229
|
}
|
206
230
|
|
207
231
|
|