質問編集履歴
1
書式の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,9 +2,21 @@
|
|
2
2
|
|
3
3
|
解らないことが有り、質問させてもらいます。
|
4
4
|
|
5
|
+
|
6
|
+
|
5
|
-
テキストエディタで、開いているファイルを
|
7
|
+
・テキストエディタで、開いているファイルを削除するボタンと保存するボタンの実装
|
8
|
+
|
9
|
+
|
10
|
+
|
6
|
-
|
11
|
+
・削除と保存するときに確認ダイアログの表示
|
12
|
+
|
13
|
+
|
14
|
+
|
7
|
-
|
15
|
+
・保存ボタンは上書き保存と新規作成それぞれに、違う確認文のダイアログが表示されようにする(上書き保存と新規作成はchoiceで選択します)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
以上なのですが、
|
8
20
|
|
9
21
|
どうすれば良いのか、皆目見当がつきません
|
10
22
|
|
@@ -12,8 +24,6 @@
|
|
12
24
|
|
13
25
|
|
14
26
|
|
15
|
-
上書き保存と新規作成はchoiceで選択します
|
16
|
-
|
17
27
|
|
18
28
|
|
19
29
|
|
@@ -24,6 +34,8 @@
|
|
24
34
|
|
25
35
|
|
26
36
|
|
37
|
+
//コンポーネントの宣言
|
38
|
+
|
27
39
|
public class Frame
|
28
40
|
|
29
41
|
JRadioButton rb = new JRadioButton("新規作成", true);
|
@@ -32,75 +44,51 @@
|
|
32
44
|
|
33
45
|
JRadioButton rb2 = new JRadioButton("削除", false);
|
34
46
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
47
|
JButton jb = new JButton("終了");
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
public JButton jb1 = new JButton("開く");
|
49
|
+
public JButton jb1 = new JButton("開く");
|
46
|
-
|
50
|
+
|
47
|
-
JButton jb2 = new JButton("クリア");
|
51
|
+
JButton jb2 = new JButton("クリア");
|
48
52
|
|
49
53
|
JButton jb3 = new JButton("削除");
|
50
54
|
|
51
|
-
JButton jb4 = new JButton("保存");
|
55
|
+
- 0. リスト JButton jb4 = new JButton("保存");
|
52
|
-
|
56
|
+
|
53
|
-
JButton jb5 = new JButton("・・・");
|
57
|
+
JButton jb5 = new JButton("・・・");
|
54
|
-
|
58
|
+
|
55
|
-
JButton jb6 = new JButton("・・・");
|
59
|
+
JButton jb6 = new JButton("・・・");
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
|
59
|
-
JLabel l1 = new JLabel("動作:");
|
61
|
+
JLabel l1 = new JLabel("動作:");
|
60
|
-
|
62
|
+
|
61
|
-
JLabel l2 = new JLabel("入力ファイル:");
|
63
|
+
JLabel l2 = new JLabel("入力ファイル:");
|
62
|
-
|
64
|
+
|
63
|
-
JLabel l3 = new JLabel("出力方法:");
|
65
|
+
JLabel l3 = new JLabel("出力方法:");
|
64
|
-
|
66
|
+
|
65
|
-
JLabel l4 = new JLabel("出力ファイル:");
|
67
|
+
JLabel l4 = new JLabel("出力ファイル:");
|
66
|
-
|
67
|
-
|
68
|
-
|
68
|
+
|
69
|
-
JTextField t = new JTextField();
|
69
|
+
JTextField t = new JTextField();
|
70
70
|
|
71
71
|
JTextField t1 = new JTextField();
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
JFileChooser jc = new JFileChooser();
|
73
|
+
JFileChooser jc = new JFileChooser();
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
|
81
|
-
Choice c = new Choice();
|
75
|
+
Choice c = new Choice();
|
82
|
-
|
83
|
-
|
84
76
|
|
85
77
|
JTextArea ta = new JTextArea();
|
86
78
|
|
87
|
-
JScrollPane sp = new JScrollPane(ta);
|
79
|
+
JScrollPane sp = new JScrollPane(ta);
|
80
|
+
|
81
|
+
|
82
|
+
|
88
|
-
|
83
|
+
//コンポーネントの配置
|
89
|
-
|
90
|
-
|
84
|
+
|
91
|
-
public Frame() {
|
85
|
+
public Frame() {
|
92
86
|
|
93
87
|
|
94
88
|
|
95
89
|
super("テキストファイル編集ツール");
|
96
90
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
91
|
+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
104
92
|
|
105
93
|
setSize(700, 500);
|
106
94
|
|
@@ -108,136 +96,120 @@
|
|
108
96
|
|
109
97
|
|
110
98
|
|
99
|
+
//パネル スクロール
|
100
|
+
|
101
|
+
JPanel p = new JPanel();
|
102
|
+
|
103
|
+
p.setLayout(null);
|
104
|
+
|
105
|
+
sp.setBounds(50, 93, 476, 227);
|
106
|
+
|
107
|
+
p.add(sp);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
//ラジオ
|
112
|
+
|
113
|
+
rb.setBounds(240, 15, 85, 20);
|
114
|
+
|
115
|
+
rb1.setBounds(335, 15, 85, 20);
|
116
|
+
|
117
|
+
rb2.setBounds(420, 15, 85, 20);
|
118
|
+
|
119
|
+
ButtonGroup gr =new ButtonGroup();
|
120
|
+
|
121
|
+
p.add(rb);
|
122
|
+
|
123
|
+
p.add(rb1);
|
124
|
+
|
125
|
+
p.add(rb2);
|
126
|
+
|
111
127
|
|
112
128
|
|
113
|
-
//パネル スクロール
|
114
|
-
|
115
|
-
JPanel p = new JPanel();
|
116
|
-
|
117
|
-
p.setLayout(null);
|
118
|
-
|
119
|
-
sp.setBounds(50, 93, 476, 227);
|
120
|
-
|
121
|
-
p.add(sp);
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
//
|
129
|
+
//ボタン
|
126
|
-
|
130
|
+
|
127
|
-
|
131
|
+
jb.setBounds(575, 50, 90, 20);
|
128
|
-
|
132
|
+
|
129
|
-
|
133
|
+
jb1.setBounds(575, 90, 90, 20);
|
130
|
-
|
134
|
+
|
131
|
-
|
135
|
+
jb2.setBounds(575, 165, 90, 30);
|
132
|
-
|
136
|
+
|
133
|
-
Bu
|
137
|
+
jb3.setBounds(575, 200, 90, 30);
|
138
|
+
|
134
|
-
|
139
|
+
jb4.setBounds(575, 340, 90, 50);
|
140
|
+
|
141
|
+
jb5.setBounds(500, 400, 20, 23);
|
142
|
+
|
143
|
+
jb6.setBounds(500, 55, 20, 23);
|
144
|
+
|
135
|
-
p.add(
|
145
|
+
p.add(jb);
|
136
|
-
|
146
|
+
|
137
|
-
p.add(
|
147
|
+
p.add(jb1);
|
138
|
-
|
148
|
+
|
139
|
-
p.add(
|
149
|
+
p.add(jb2);
|
150
|
+
|
151
|
+
p.add(jb3);
|
152
|
+
|
153
|
+
p.add(jb4);
|
154
|
+
|
155
|
+
p.add(jb5);
|
156
|
+
|
157
|
+
p.add(jb6);
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
//ラベル
|
162
|
+
|
163
|
+
l1.setBounds(180, 17, 50, 15);
|
164
|
+
|
165
|
+
l2.setBounds(75, 55, 100, 15);
|
166
|
+
|
167
|
+
l3.setBounds(100, 350, 80, 30);
|
168
|
+
|
169
|
+
l4.setBounds(80, 400, 100, 15);
|
170
|
+
|
171
|
+
p.add(l1);
|
172
|
+
|
173
|
+
p.add(l2);
|
174
|
+
|
175
|
+
p.add(l3);
|
176
|
+
|
177
|
+
p.add(l4);
|
140
178
|
|
141
179
|
|
142
180
|
|
181
|
+
//テキストエリア
|
182
|
+
|
183
|
+
t.setBounds(174, 55, 320, 23);
|
184
|
+
|
185
|
+
t1.setBounds(174, 400, 323, 23);
|
186
|
+
|
187
|
+
p.add(t);
|
188
|
+
|
189
|
+
p.add(t1);
|
190
|
+
|
143
191
|
|
144
192
|
|
145
|
-
//
|
193
|
+
//チョイス
|
146
|
-
|
194
|
+
|
147
|
-
|
195
|
+
c .setBounds(174, 352, 323, 19);
|
148
|
-
|
196
|
+
|
149
|
-
|
197
|
+
c.add("名前を付けて保存");
|
150
|
-
|
198
|
+
|
151
|
-
|
199
|
+
c.add("上書き保存");
|
152
|
-
|
153
|
-
|
200
|
+
|
154
|
-
|
155
|
-
jb4.setBounds(575, 340, 90, 50);
|
156
|
-
|
157
|
-
jb5.setBounds(500, 400, 20, 23);
|
158
|
-
|
159
|
-
jb6.setBounds(500, 55, 20, 23);
|
160
|
-
|
161
|
-
p.add(
|
201
|
+
p.add(c);
|
162
|
-
|
202
|
+
|
203
|
+
|
204
|
+
|
163
|
-
|
205
|
+
jb.addActionListener(this);
|
164
|
-
|
165
|
-
|
206
|
+
|
166
|
-
|
167
|
-
p.add(jb3);
|
168
|
-
|
169
|
-
p.add(jb4);
|
170
|
-
|
171
|
-
p.add(jb5);
|
172
|
-
|
173
|
-
p.add(jb6);
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
//ラベル
|
180
|
-
|
181
|
-
|
207
|
+
jb1.addActionListener(this);
|
182
|
-
|
208
|
+
|
183
|
-
|
209
|
+
jb2.addActionListener(this);
|
184
|
-
|
185
|
-
l3.setBounds(100, 350, 80, 30);
|
186
|
-
|
187
|
-
l4.setBounds(80, 400, 100, 15);
|
188
|
-
|
189
|
-
p.add(l1);
|
190
|
-
|
191
|
-
p.add(l2);
|
192
|
-
|
193
|
-
p.add(l3);
|
194
|
-
|
195
|
-
p.add(l4);
|
196
210
|
|
197
211
|
|
198
212
|
|
199
|
-
//テキストエリア
|
200
|
-
|
201
|
-
t.setBounds(174, 55, 320, 23);
|
202
|
-
|
203
|
-
t1.setBounds(174, 400, 323, 23);
|
204
|
-
|
205
|
-
p.add(t);
|
206
|
-
|
207
|
-
p.add(t1);
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
//チョイス
|
212
|
-
|
213
|
-
c .setBounds(174, 352, 323, 19);
|
214
|
-
|
215
|
-
c.add("名前を付けて保存");
|
216
|
-
|
217
|
-
c.add("上書き保存");
|
218
|
-
|
219
|
-
p.add(c);
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
jb.addActionListener(this);
|
234
|
-
|
235
|
-
jb1.addActionListener(this);
|
236
|
-
|
237
|
-
jb2.addActionListener(this);
|
238
|
-
|
239
|
-
|
240
|
-
|
241
213
|
jb4.addActionListener(this);
|
242
214
|
|
243
215
|
|
@@ -254,13 +226,9 @@
|
|
254
226
|
|
255
227
|
}
|
256
228
|
|
257
|
-
|
229
|
+
//ボタンが押されたときの処理
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
230
|
+
|
263
|
-
|
231
|
+
public void actionPerformed(ActionEvent e) {
|
264
232
|
|
265
233
|
|
266
234
|
|
@@ -306,7 +274,7 @@
|
|
306
274
|
|
307
275
|
|
308
276
|
|
309
|
-
|
277
|
+
//ファイルを開くメソッド
|
310
278
|
|
311
279
|
void openFile() {
|
312
280
|
|
@@ -340,7 +308,7 @@
|
|
340
308
|
|
341
309
|
}
|
342
310
|
|
343
|
-
|
311
|
+
//ファイルを保存するメソッド
|
344
312
|
|
345
313
|
void saveFile() {
|
346
314
|
|