質問編集履歴

7

意図的に内容を抹消する行為にあたるため

2021/07/26 07:39

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- 解決すことができました。
1
+ 1.ページを進め方法
test CHANGED
@@ -1,29 +1,175 @@
1
1
  ### 前提・実現したいこと
2
-
3
- 解決しました。
4
-
5
-
6
-
7
-
8
-
9
-
10
2
 
11
3
  ### 発生している問題・エラーメッセージ
12
4
 
5
+ ```
13
6
 
7
+ エラーメッセージ
14
8
 
15
-
9
+ ```
16
-
17
-
18
10
 
19
11
  ### 該当のソースコード
20
12
 
13
+ 検索
21
14
 
15
+ ```
22
16
 
17
+ public void actionPerformed(ActionEvent e) {
23
18
 
19
+ // TODO 自動生成されたメソッド・スタブ
20
+
21
+
22
+
23
+ readBook();
24
+
25
+
26
+
27
+ //オブジェクト型の配列生成
28
+
29
+ Book bk[] = new Book[4];
30
+
31
+ bk[0] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
32
+
33
+ bk[1] = new Book(data[1][0], data[1][1], data[1][2], data[1][3], data[1][4]);
34
+
35
+ bk[2] = new Book(data[2][0], data[2][1], data[2][2], data[2][3], data[2][4]);
36
+
37
+ bk[3] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
38
+
39
+
40
+
41
+ //検索文字列を取得
42
+
43
+ String gStr = text1.getText();
44
+
45
+
46
+
47
+ //部分文字列検索
48
+
49
+ int result1 = book1.getTitle().indexOf(gStr);
50
+
51
+ int result2 = book1.getAuthor().indexOf(gStr);
52
+
53
+ int result3 = book1.getPublisher().indexOf(gStr);
54
+
55
+ int result4 = book1.getYop().indexOf(gStr);
56
+
57
+ int result5 = book1.getIsbn().indexOf(gStr);
58
+
59
+ int result6 = book2.getTitle().indexOf(gStr);
60
+
61
+ int result7 = book2.getAuthor().indexOf(gStr);
62
+
63
+ int result8 = book2.getPublisher().indexOf(gStr);
64
+
65
+ int result9 = book2.getYop().indexOf(gStr);
66
+
67
+ int result10 = book2.getIsbn().indexOf(gStr);
68
+
69
+ int result11 = book3.getTitle().indexOf(gStr);
70
+
71
+ int result12 = book3.getAuthor().indexOf(gStr);
72
+
73
+ int result13 = book3.getPublisher().indexOf(gStr);
74
+
75
+ int result14 = book3.getYop().indexOf(gStr);
76
+
77
+ int result15 = book3.getIsbn().indexOf(gStr);
78
+
79
+ int result16 = book4.getTitle().indexOf(gStr);
80
+
81
+ int result17 = book4.getAuthor().indexOf(gStr);
82
+
83
+ int result18 = book4.getPublisher().indexOf(gStr);
84
+
85
+ int result19 = book4.getYop().indexOf(gStr);
86
+
87
+ int result20 = book4.getIsbn().indexOf(gStr);
88
+
89
+
90
+
91
+ if (e.getSource() == button1) { //検索ボタン
92
+
93
+ if (result1 != -1 || result2 != -1 || result3 != -1 || result4 != -1 || result5 != -1) {
94
+
95
+ text2.setText(book1.getTitle());
96
+
97
+ text3.setText(book1.getAuthor());
98
+
99
+ text4.setText(book1.getPublisher());
100
+
101
+ text5.setText(book1.getYop());
102
+
103
+ text6.setText(book1.getIsbn());
104
+
105
+ }
106
+
107
+
108
+
109
+ } else if (e.getSource() == button3) { //進むボタン
110
+
111
+ for (int i = 0; i < 3; i++) {
112
+
113
+ if ((result6 != -1 || result7 != -1 || result8 != -1 || result9 != -1 || result10 != -1) && i == 0) {
114
+
115
+ text2.setText(book2.getTitle());
116
+
117
+ text3.setText(book2.getAuthor());
118
+
119
+ text4.setText(book2.getPublisher());
120
+
121
+ text5.setText(book2.getYop());
122
+
123
+ text6.setText(book2.getIsbn());
124
+
125
+ } else if ((result11 != -1 || result12 != -1 || result13 != -1 || result14 != -1 || result15 != -1)
126
+
127
+ && i == 1) {
128
+
129
+ text2.setText(book3.getTitle());
130
+
131
+ text3.setText(book3.getAuthor());
132
+
133
+ text4.setText(book3.getPublisher());
134
+
135
+ text5.setText(book3.getYop());
136
+
137
+ text6.setText(book3.getIsbn());
138
+
139
+ }
140
+
141
+ }
142
+
143
+ } else if (e.getSource() == button2) { //戻るボタン
144
+
145
+ if ((result11 != -1 || result2 != -1 || result3 != -1 || result4 != -1 || result5 != -1)) {
146
+
147
+ text2.setText(book1.getTitle());
148
+
149
+ text3.setText(book1.getAuthor());
150
+
151
+ text4.setText(book1.getPublisher());
152
+
153
+ text5.setText(book1.getYop());
154
+
155
+ text6.setText(book1.getIsbn());
156
+
157
+ }
158
+
159
+
160
+
161
+ }
162
+
163
+ }
164
+
165
+ }
166
+
167
+
168
+
169
+ ```
170
+
171
+
24
172
 
25
173
  ### 試したこと
26
174
 
27
-
28
-
29
175
  ### 補足情報(FW/ツールのバージョンなど)

6

書式の改善

2021/07/26 07:39

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
File without changes

5

書籍の改善

2021/07/21 17:09

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- 1.ページを進め方法
1
+ 解決すことができました。
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
- 複数の蔵書がマッチした場合、進むボタンを押すと2個目、3個目の蔵書情報がテキストフィールドに表示でき、戻るボタンを押すと前の蔵書情報を表示する方法を教えて頂きたいです
3
+ 解決ました。
4
4
 
5
5
 
6
6
 
@@ -12,11 +12,7 @@
12
12
 
13
13
 
14
14
 
15
- ```
16
15
 
17
- エラーメッセージ
18
-
19
- ```
20
16
 
21
17
 
22
18
 
@@ -26,166 +22,6 @@
26
22
 
27
23
 
28
24
 
29
- 検索
30
-
31
- ```
32
-
33
- public void actionPerformed(ActionEvent e) {
34
-
35
- // TODO 自動生成されたメソッド・スタブ
36
-
37
-
38
-
39
- readBook();
40
-
41
-
42
-
43
- //オブジェクト型の配列生成
44
-
45
- Book bk[] = new Book[4];
46
-
47
- bk[0] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
48
-
49
- bk[1] = new Book(data[1][0], data[1][1], data[1][2], data[1][3], data[1][4]);
50
-
51
- bk[2] = new Book(data[2][0], data[2][1], data[2][2], data[2][3], data[2][4]);
52
-
53
- bk[3] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
54
-
55
-
56
-
57
- //検索文字列を取得
58
-
59
- String gStr = text1.getText();
60
-
61
-
62
-
63
- //部分文字列検索
64
-
65
- int result1 = book1.getTitle().indexOf(gStr);
66
-
67
- int result2 = book1.getAuthor().indexOf(gStr);
68
-
69
- int result3 = book1.getPublisher().indexOf(gStr);
70
-
71
- int result4 = book1.getYop().indexOf(gStr);
72
-
73
- int result5 = book1.getIsbn().indexOf(gStr);
74
-
75
- int result6 = book2.getTitle().indexOf(gStr);
76
-
77
- int result7 = book2.getAuthor().indexOf(gStr);
78
-
79
- int result8 = book2.getPublisher().indexOf(gStr);
80
-
81
- int result9 = book2.getYop().indexOf(gStr);
82
-
83
- int result10 = book2.getIsbn().indexOf(gStr);
84
-
85
- int result11 = book3.getTitle().indexOf(gStr);
86
-
87
- int result12 = book3.getAuthor().indexOf(gStr);
88
-
89
- int result13 = book3.getPublisher().indexOf(gStr);
90
-
91
- int result14 = book3.getYop().indexOf(gStr);
92
-
93
- int result15 = book3.getIsbn().indexOf(gStr);
94
-
95
- int result16 = book4.getTitle().indexOf(gStr);
96
-
97
- int result17 = book4.getAuthor().indexOf(gStr);
98
-
99
- int result18 = book4.getPublisher().indexOf(gStr);
100
-
101
- int result19 = book4.getYop().indexOf(gStr);
102
-
103
- int result20 = book4.getIsbn().indexOf(gStr);
104
-
105
-
106
-
107
- if (e.getSource() == button1) { //検索ボタン
108
-
109
- if (result1 != -1 || result2 != -1 || result3 != -1 || result4 != -1 || result5 != -1) {
110
-
111
- text2.setText(book1.getTitle());
112
-
113
- text3.setText(book1.getAuthor());
114
-
115
- text4.setText(book1.getPublisher());
116
-
117
- text5.setText(book1.getYop());
118
-
119
- text6.setText(book1.getIsbn());
120
-
121
- }
122
-
123
-
124
-
125
- } else if (e.getSource() == button3) { //進むボタン
126
-
127
- for (int i = 0; i < 3; i++) {
128
-
129
- if ((result6 != -1 || result7 != -1 || result8 != -1 || result9 != -1 || result10 != -1) && i == 0) {
130
-
131
- text2.setText(book2.getTitle());
132
-
133
- text3.setText(book2.getAuthor());
134
-
135
- text4.setText(book2.getPublisher());
136
-
137
- text5.setText(book2.getYop());
138
-
139
- text6.setText(book2.getIsbn());
140
-
141
- } else if ((result11 != -1 || result12 != -1 || result13 != -1 || result14 != -1 || result15 != -1)
142
-
143
- && i == 1) {
144
-
145
- text2.setText(book3.getTitle());
146
-
147
- text3.setText(book3.getAuthor());
148
-
149
- text4.setText(book3.getPublisher());
150
-
151
- text5.setText(book3.getYop());
152
-
153
- text6.setText(book3.getIsbn());
154
-
155
- }
156
-
157
- }
158
-
159
- } else if (e.getSource() == button2) { //戻るボタン
160
-
161
- if ((result11 != -1 || result2 != -1 || result3 != -1 || result4 != -1 || result5 != -1)) {
162
-
163
- text2.setText(book1.getTitle());
164
-
165
- text3.setText(book1.getAuthor());
166
-
167
- text4.setText(book1.getPublisher());
168
-
169
- text5.setText(book1.getYop());
170
-
171
- text6.setText(book1.getIsbn());
172
-
173
- }
174
-
175
-
176
-
177
- }
178
-
179
- }
180
-
181
- }
182
-
183
-
184
-
185
- ```
186
-
187
-
188
-
189
25
  ### 試したこと
190
26
 
191
27
 

4

書式の改善

2021/07/21 17:08

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -29,448 +29,6 @@
29
29
  検索
30
30
 
31
31
  ```
32
-
33
- import java.awt.BorderLayout;
34
-
35
- import java.awt.Container;
36
-
37
- import java.awt.GridBagConstraints;
38
-
39
- import java.awt.GridBagLayout;
40
-
41
- import java.awt.Insets;
42
-
43
- import java.awt.event.ActionEvent;
44
-
45
- import java.awt.event.ActionListener;
46
-
47
- import java.io.BufferedReader;
48
-
49
- import java.io.File;
50
-
51
- import java.io.FileReader;
52
-
53
-
54
-
55
- import javax.swing.JButton;
56
-
57
- import javax.swing.JFrame; //フレーム
58
-
59
- import javax.swing.JLabel;
60
-
61
- import javax.swing.JPanel;
62
-
63
- import javax.swing.JTextField;
64
-
65
-
66
-
67
- public class BookData extends JFrame implements ActionListener {
68
-
69
-
70
-
71
- private GridBagLayout grLayout;
72
-
73
- private GridBagConstraints gbc;
74
-
75
- private Container cntnr;
76
-
77
- private JLabel label1, label2, label3, label4, label5, label6, label7;
78
-
79
- private JPanel panel1;
80
-
81
- private JButton button1, button2, button3, button4;
82
-
83
- private JTextField text1, text2, text3, text4, text5, text6;
84
-
85
-
86
-
87
- public String data[][];
88
-
89
-
90
-
91
- // コンストラクタ:窓のタイトル,位置,大きさを設定
92
-
93
- BookData(String title) {
94
-
95
- super(title);
96
-
97
- setBounds(200, 200, 800, 400);
98
-
99
- }
100
-
101
-
102
-
103
- public static void main(String[] args) {
104
-
105
- // TODO 自動生成されたメソッド・スタブ
106
-
107
-
108
-
109
- //自クラスインスタンス生成
110
-
111
- BookData frame;
112
-
113
-
114
-
115
- frame = new BookData("Seach Book"); //タイトル
116
-
117
-
118
-
119
- frame.defineVal(); //表示準備
120
-
121
- frame.setVisible(true); //表示
122
-
123
-
124
-
125
- }
126
-
127
-
128
-
129
- public void readBook() { //csvファイルを読み込み
130
-
131
-
132
-
133
- BufferedReader br = null;
134
-
135
- String read_file = "booklist.csv";
136
-
137
- final int MAX_DATA_NUMS = 100;
138
-
139
- data = new String[MAX_DATA_NUMS][];
140
-
141
- try {
142
-
143
- File file = new File(read_file);
144
-
145
- br = new BufferedReader(new FileReader(file));
146
-
147
-
148
-
149
- int index = 0;
150
-
151
- String line;
152
-
153
- while ((line = br.readLine()) != null) {
154
-
155
- data[index] = line.split(",");
156
-
157
- index++;
158
-
159
- }
160
-
161
- } catch (Exception e) {
162
-
163
- System.out.println(e.getMessage());
164
-
165
- } finally {
166
-
167
- try {
168
-
169
- br.close();
170
-
171
- } catch (Exception e) {
172
-
173
- System.out.println(e.getMessage());
174
-
175
- }
176
-
177
- }
178
-
179
-
180
-
181
- for (int i = 0; i < MAX_DATA_NUMS; i++) {
182
-
183
- if (data[i] == null)
184
-
185
- break;
186
-
187
- for (int j = 0; j < data[i].length; j++) {
188
-
189
- this.data[i][j] = data[i][j]; //配列に格納
190
-
191
- }
192
-
193
- }
194
-
195
- }
196
-
197
-
198
-
199
- private void defineVal() { //レイアウト
200
-
201
-
202
-
203
- cntnr = getContentPane();
204
-
205
- grLayout = new GridBagLayout();
206
-
207
- gbc = new GridBagConstraints();
208
-
209
- panel1 = new JPanel();
210
-
211
- panel1.setLayout(grLayout);
212
-
213
-
214
-
215
- label1 = new JLabel("検索語:");
216
-
217
- label2 = new JLabel("結果:");
218
-
219
- label3 = new JLabel("タイトル:");
220
-
221
- label4 = new JLabel("著者:");
222
-
223
- label5 = new JLabel("出版社:");
224
-
225
- label6 = new JLabel("出版年:");
226
-
227
- label7 = new JLabel("ISBN:");
228
-
229
-
230
-
231
- text1 = new JTextField(50);
232
-
233
- text2 = new JTextField(50);
234
-
235
- text3 = new JTextField(50);
236
-
237
- text4 = new JTextField(50);
238
-
239
- text5 = new JTextField(50);
240
-
241
- text6 = new JTextField(50);
242
-
243
-
244
-
245
- button1 = new JButton("検索");
246
-
247
- button2 = new JButton("<");
248
-
249
- button3 = new JButton(">");
250
-
251
- button4 = new JButton("検索結果保存");
252
-
253
-
254
-
255
- //レイアウト
256
-
257
- gbc.weighty = 0.3d;
258
-
259
-
260
-
261
- gbc.gridx = 0;
262
-
263
- gbc.gridy = 0;
264
-
265
- grLayout.setConstraints(label1, gbc);
266
-
267
-
268
-
269
- gbc.gridx = 1;
270
-
271
- gbc.gridy = 0;
272
-
273
- grLayout.setConstraints(text1, gbc);
274
-
275
-
276
-
277
- gbc.gridx = 2;
278
-
279
- gbc.gridy = 0;
280
-
281
- grLayout.setConstraints(button1, gbc);
282
-
283
-
284
-
285
- gbc.gridx = 0;
286
-
287
- gbc.gridy = 1;
288
-
289
- grLayout.setConstraints(label2, gbc);
290
-
291
-
292
-
293
- gbc.gridx = 0;
294
-
295
- gbc.gridy = 2;
296
-
297
- grLayout.setConstraints(label3, gbc);
298
-
299
-
300
-
301
- gbc.gridx = 1;
302
-
303
- gbc.gridy = 2;
304
-
305
- grLayout.setConstraints(text2, gbc);
306
-
307
-
308
-
309
- gbc.gridx = 0;
310
-
311
- gbc.gridy = 3;
312
-
313
- grLayout.setConstraints(label4, gbc);
314
-
315
-
316
-
317
- gbc.gridx = 1;
318
-
319
- gbc.gridy = 3;
320
-
321
- grLayout.setConstraints(text3, gbc);
322
-
323
-
324
-
325
- gbc.gridx = 0;
326
-
327
- gbc.gridy = 4;
328
-
329
- grLayout.setConstraints(label5, gbc);
330
-
331
-
332
-
333
- gbc.gridx = 1;
334
-
335
- gbc.gridy = 4;
336
-
337
- grLayout.setConstraints(text4, gbc);
338
-
339
-
340
-
341
- gbc.gridx = 0;
342
-
343
- gbc.gridy = 5;
344
-
345
- grLayout.setConstraints(label6, gbc);
346
-
347
-
348
-
349
- gbc.gridx = 1;
350
-
351
- gbc.gridy = 5;
352
-
353
- grLayout.setConstraints(text5, gbc);
354
-
355
-
356
-
357
- gbc.gridx = 0;
358
-
359
- gbc.gridy = 6;
360
-
361
- grLayout.setConstraints(label7, gbc);
362
-
363
-
364
-
365
- gbc.gridx = 1;
366
-
367
- gbc.gridy = 6;
368
-
369
- grLayout.setConstraints(text6, gbc);
370
-
371
-
372
-
373
- gbc.gridx = 1;
374
-
375
- gbc.gridy = 7;
376
-
377
- gbc.anchor = GridBagConstraints.WEST;
378
-
379
- gbc.insets = new Insets(0, 150, 0, 0);
380
-
381
- grLayout.setConstraints(button2, gbc);
382
-
383
-
384
-
385
- gbc.gridx = 1;
386
-
387
- gbc.gridy = 7;
388
-
389
- gbc.anchor = GridBagConstraints.CENTER;
390
-
391
- gbc.insets = new Insets(0, 0, 0, 0);
392
-
393
- grLayout.setConstraints(button3, gbc);
394
-
395
-
396
-
397
- gbc.gridx = 1;
398
-
399
- gbc.gridy = 7;
400
-
401
- gbc.anchor = GridBagConstraints.EAST;
402
-
403
- gbc.insets = new Insets(0, 0, 0, 50);
404
-
405
- grLayout.setConstraints(button4, gbc);
406
-
407
-
408
-
409
- panel1.add(label1);
410
-
411
- panel1.add(label2);
412
-
413
- panel1.add(label3);
414
-
415
- panel1.add(label4);
416
-
417
- panel1.add(label5);
418
-
419
- panel1.add(label6);
420
-
421
- panel1.add(label7);
422
-
423
-
424
-
425
- panel1.add(text1);
426
-
427
- panel1.add(text2);
428
-
429
- panel1.add(text3);
430
-
431
- panel1.add(text4);
432
-
433
- panel1.add(text5);
434
-
435
- panel1.add(text6);
436
-
437
-
438
-
439
- panel1.add(button1);
440
-
441
- panel1.add(button2);
442
-
443
- panel1.add(button3);
444
-
445
- panel1.add(button4);
446
-
447
-
448
-
449
- cntnr.add(panel1, BorderLayout.CENTER);
450
-
451
-
452
-
453
- button1.addActionListener(this);
454
-
455
- button2.addActionListener(this);
456
-
457
- button3.addActionListener(this);
458
-
459
- button4.addActionListener(this);
460
-
461
-
462
-
463
- //窓を閉じたとき、プログラム終了
464
-
465
- setDefaultCloseOperation(EXIT_ON_CLOSE);
466
-
467
-
468
-
469
- }
470
-
471
-
472
-
473
- @Override
474
32
 
475
33
  public void actionPerformed(ActionEvent e) {
476
34
 

3

書式の改善

2021/07/21 16:51

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- Java ボタンでページめる方法
1
+ 1.ページを進める方法
test CHANGED
@@ -1,10 +1,6 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
- javaで蔵書を検索するとcsvファイルから部分検索にマッチした蔵書情報をテキストフィールドに表示するプログラムを作っています。例えば、タイトル,出版社,著者です。
4
-
5
- この時、複数の蔵書がマッチした場合、進むボタンを押すと2個目、3個目の蔵書情報がテキストフィールドに表示でき、戻るボタンを押すと前の蔵書情報を表示する方法を教えて頂きたいです。
3
+ 複数の蔵書がマッチした場合、進むボタンを押すと2個目、3個目の蔵書情報がテキストフィールドに表示でき、戻るボタンを押すと前の蔵書情報を表示する方法を教えて頂きたいです。
6
-
7
- 環境はeclipseです。
8
4
 
9
5
 
10
6
 
@@ -26,746 +22,614 @@
26
22
 
27
23
  ### 該当のソースコード
28
24
 
25
+
26
+
27
+
28
+
29
- 蔵書データ
29
+ 検索
30
-
30
+
31
- `````````
31
+ ```
32
+
32
-
33
+ import java.awt.BorderLayout;
34
+
35
+ import java.awt.Container;
36
+
37
+ import java.awt.GridBagConstraints;
38
+
39
+ import java.awt.GridBagLayout;
40
+
41
+ import java.awt.Insets;
42
+
43
+ import java.awt.event.ActionEvent;
44
+
45
+ import java.awt.event.ActionListener;
46
+
47
+ import java.io.BufferedReader;
48
+
33
- public class Book {
49
+ import java.io.File;
50
+
34
-
51
+ import java.io.FileReader;
52
+
53
+
54
+
35
-
55
+ import javax.swing.JButton;
56
+
36
-
57
+ import javax.swing.JFrame; //フレーム
58
+
59
+ import javax.swing.JLabel;
60
+
61
+ import javax.swing.JPanel;
62
+
63
+ import javax.swing.JTextField;
64
+
65
+
66
+
67
+ public class BookData extends JFrame implements ActionListener {
68
+
69
+
70
+
71
+ private GridBagLayout grLayout;
72
+
37
- private String title;
73
+ private GridBagConstraints gbc;
38
-
74
+
39
- private String author;
75
+ private Container cntnr;
40
-
76
+
41
- private String publisher;
77
+ private JLabel label1, label2, label3, label4, label5, label6, label7;
42
-
43
- private String yop;
78
+
44
-
45
- private String isbn;
79
+ private JPanel panel1;
80
+
46
-
81
+ private JButton button1, button2, button3, button4;
47
-
48
-
82
+
49
- public Book(String title, String author, String publisher, String yop, String isbn) {
83
+ private JTextField text1, text2, text3, text4, text5, text6;
84
+
85
+
86
+
50
-
87
+ public String data[][];
88
+
89
+
90
+
91
+ // コンストラクタ:窓のタイトル,位置,大きさを設定
92
+
51
- this.title = title;
93
+ BookData(String title) {
52
-
94
+
53
- this.author = author;
95
+ super(title);
54
-
96
+
55
- this.publisher = publisher;
97
+ setBounds(200, 200, 800, 400);
56
-
57
- this.yop = yop;
58
-
59
- this.isbn = isbn;
60
98
 
61
99
  }
62
100
 
63
101
 
64
102
 
65
- public String getTitle() {
103
+ public static void main(String[] args) {
104
+
66
-
105
+ // TODO 自動生成されたメソッド・スタブ
106
+
107
+
108
+
109
+ //自クラスインスタンス生成
110
+
67
- return title;
111
+ BookData frame;
112
+
113
+
114
+
115
+ frame = new BookData("Seach Book"); //タイトル
116
+
117
+
118
+
119
+ frame.defineVal(); //表示準備
120
+
121
+ frame.setVisible(true); //表示
122
+
123
+
68
124
 
69
125
  }
70
126
 
71
127
 
72
128
 
129
+ public void readBook() { //csvファイルを読み込み
130
+
131
+
132
+
133
+ BufferedReader br = null;
134
+
135
+ String read_file = "booklist.csv";
136
+
137
+ final int MAX_DATA_NUMS = 100;
138
+
139
+ data = new String[MAX_DATA_NUMS][];
140
+
141
+ try {
142
+
73
- public void setTitle(String title) {
143
+ File file = new File(read_file);
144
+
74
-
145
+ br = new BufferedReader(new FileReader(file));
146
+
147
+
148
+
75
- this.title = title;
149
+ int index = 0;
150
+
151
+ String line;
152
+
153
+ while ((line = br.readLine()) != null) {
154
+
155
+ data[index] = line.split(",");
156
+
157
+ index++;
158
+
159
+ }
160
+
161
+ } catch (Exception e) {
162
+
163
+ System.out.println(e.getMessage());
164
+
165
+ } finally {
166
+
167
+ try {
168
+
169
+ br.close();
170
+
171
+ } catch (Exception e) {
172
+
173
+ System.out.println(e.getMessage());
174
+
175
+ }
176
+
177
+ }
178
+
179
+
180
+
181
+ for (int i = 0; i < MAX_DATA_NUMS; i++) {
182
+
183
+ if (data[i] == null)
184
+
185
+ break;
186
+
187
+ for (int j = 0; j < data[i].length; j++) {
188
+
189
+ this.data[i][j] = data[i][j]; //配列に格納
190
+
191
+ }
192
+
193
+ }
76
194
 
77
195
  }
78
196
 
79
197
 
80
198
 
199
+ private void defineVal() { //レイアウト
200
+
201
+
202
+
203
+ cntnr = getContentPane();
204
+
205
+ grLayout = new GridBagLayout();
206
+
207
+ gbc = new GridBagConstraints();
208
+
209
+ panel1 = new JPanel();
210
+
81
- public String getAuthor() {
211
+ panel1.setLayout(grLayout);
212
+
213
+
214
+
82
-
215
+ label1 = new JLabel("検索語:");
216
+
217
+ label2 = new JLabel("結果:");
218
+
219
+ label3 = new JLabel("タイトル:");
220
+
221
+ label4 = new JLabel("著者:");
222
+
223
+ label5 = new JLabel("出版社:");
224
+
225
+ label6 = new JLabel("出版年:");
226
+
227
+ label7 = new JLabel("ISBN:");
228
+
229
+
230
+
231
+ text1 = new JTextField(50);
232
+
233
+ text2 = new JTextField(50);
234
+
235
+ text3 = new JTextField(50);
236
+
237
+ text4 = new JTextField(50);
238
+
239
+ text5 = new JTextField(50);
240
+
241
+ text6 = new JTextField(50);
242
+
243
+
244
+
245
+ button1 = new JButton("検索");
246
+
247
+ button2 = new JButton("<");
248
+
249
+ button3 = new JButton(">");
250
+
251
+ button4 = new JButton("検索結果保存");
252
+
253
+
254
+
255
+ //レイアウト
256
+
257
+ gbc.weighty = 0.3d;
258
+
259
+
260
+
261
+ gbc.gridx = 0;
262
+
263
+ gbc.gridy = 0;
264
+
265
+ grLayout.setConstraints(label1, gbc);
266
+
267
+
268
+
269
+ gbc.gridx = 1;
270
+
271
+ gbc.gridy = 0;
272
+
273
+ grLayout.setConstraints(text1, gbc);
274
+
275
+
276
+
277
+ gbc.gridx = 2;
278
+
279
+ gbc.gridy = 0;
280
+
281
+ grLayout.setConstraints(button1, gbc);
282
+
283
+
284
+
285
+ gbc.gridx = 0;
286
+
287
+ gbc.gridy = 1;
288
+
289
+ grLayout.setConstraints(label2, gbc);
290
+
291
+
292
+
293
+ gbc.gridx = 0;
294
+
295
+ gbc.gridy = 2;
296
+
297
+ grLayout.setConstraints(label3, gbc);
298
+
299
+
300
+
301
+ gbc.gridx = 1;
302
+
303
+ gbc.gridy = 2;
304
+
305
+ grLayout.setConstraints(text2, gbc);
306
+
307
+
308
+
309
+ gbc.gridx = 0;
310
+
311
+ gbc.gridy = 3;
312
+
313
+ grLayout.setConstraints(label4, gbc);
314
+
315
+
316
+
317
+ gbc.gridx = 1;
318
+
319
+ gbc.gridy = 3;
320
+
321
+ grLayout.setConstraints(text3, gbc);
322
+
323
+
324
+
325
+ gbc.gridx = 0;
326
+
327
+ gbc.gridy = 4;
328
+
329
+ grLayout.setConstraints(label5, gbc);
330
+
331
+
332
+
333
+ gbc.gridx = 1;
334
+
335
+ gbc.gridy = 4;
336
+
337
+ grLayout.setConstraints(text4, gbc);
338
+
339
+
340
+
341
+ gbc.gridx = 0;
342
+
343
+ gbc.gridy = 5;
344
+
345
+ grLayout.setConstraints(label6, gbc);
346
+
347
+
348
+
349
+ gbc.gridx = 1;
350
+
351
+ gbc.gridy = 5;
352
+
353
+ grLayout.setConstraints(text5, gbc);
354
+
355
+
356
+
357
+ gbc.gridx = 0;
358
+
359
+ gbc.gridy = 6;
360
+
361
+ grLayout.setConstraints(label7, gbc);
362
+
363
+
364
+
365
+ gbc.gridx = 1;
366
+
367
+ gbc.gridy = 6;
368
+
369
+ grLayout.setConstraints(text6, gbc);
370
+
371
+
372
+
373
+ gbc.gridx = 1;
374
+
375
+ gbc.gridy = 7;
376
+
377
+ gbc.anchor = GridBagConstraints.WEST;
378
+
379
+ gbc.insets = new Insets(0, 150, 0, 0);
380
+
381
+ grLayout.setConstraints(button2, gbc);
382
+
383
+
384
+
385
+ gbc.gridx = 1;
386
+
387
+ gbc.gridy = 7;
388
+
389
+ gbc.anchor = GridBagConstraints.CENTER;
390
+
391
+ gbc.insets = new Insets(0, 0, 0, 0);
392
+
393
+ grLayout.setConstraints(button3, gbc);
394
+
395
+
396
+
397
+ gbc.gridx = 1;
398
+
399
+ gbc.gridy = 7;
400
+
401
+ gbc.anchor = GridBagConstraints.EAST;
402
+
403
+ gbc.insets = new Insets(0, 0, 0, 50);
404
+
405
+ grLayout.setConstraints(button4, gbc);
406
+
407
+
408
+
409
+ panel1.add(label1);
410
+
411
+ panel1.add(label2);
412
+
413
+ panel1.add(label3);
414
+
415
+ panel1.add(label4);
416
+
417
+ panel1.add(label5);
418
+
419
+ panel1.add(label6);
420
+
421
+ panel1.add(label7);
422
+
423
+
424
+
425
+ panel1.add(text1);
426
+
427
+ panel1.add(text2);
428
+
429
+ panel1.add(text3);
430
+
431
+ panel1.add(text4);
432
+
433
+ panel1.add(text5);
434
+
435
+ panel1.add(text6);
436
+
437
+
438
+
83
- return author;
439
+ panel1.add(button1);
440
+
441
+ panel1.add(button2);
442
+
443
+ panel1.add(button3);
444
+
445
+ panel1.add(button4);
446
+
447
+
448
+
449
+ cntnr.add(panel1, BorderLayout.CENTER);
450
+
451
+
452
+
453
+ button1.addActionListener(this);
454
+
455
+ button2.addActionListener(this);
456
+
457
+ button3.addActionListener(this);
458
+
459
+ button4.addActionListener(this);
460
+
461
+
462
+
463
+ //窓を閉じたとき、プログラム終了
464
+
465
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
466
+
467
+
84
468
 
85
469
  }
86
470
 
87
471
 
88
472
 
473
+ @Override
474
+
89
- public void setAuthor(String author) {
475
+ public void actionPerformed(ActionEvent e) {
476
+
90
-
477
+ // TODO 自動生成されたメソッド・スタブ
478
+
479
+
480
+
481
+ readBook();
482
+
483
+
484
+
485
+ //オブジェクト型の配列生成
486
+
487
+ Book bk[] = new Book[4];
488
+
489
+ bk[0] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
490
+
491
+ bk[1] = new Book(data[1][0], data[1][1], data[1][2], data[1][3], data[1][4]);
492
+
493
+ bk[2] = new Book(data[2][0], data[2][1], data[2][2], data[2][3], data[2][4]);
494
+
495
+ bk[3] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
496
+
497
+
498
+
499
+ //検索文字列を取得
500
+
501
+ String gStr = text1.getText();
502
+
503
+
504
+
505
+ //部分文字列検索
506
+
507
+ int result1 = book1.getTitle().indexOf(gStr);
508
+
509
+ int result2 = book1.getAuthor().indexOf(gStr);
510
+
511
+ int result3 = book1.getPublisher().indexOf(gStr);
512
+
513
+ int result4 = book1.getYop().indexOf(gStr);
514
+
515
+ int result5 = book1.getIsbn().indexOf(gStr);
516
+
517
+ int result6 = book2.getTitle().indexOf(gStr);
518
+
519
+ int result7 = book2.getAuthor().indexOf(gStr);
520
+
521
+ int result8 = book2.getPublisher().indexOf(gStr);
522
+
523
+ int result9 = book2.getYop().indexOf(gStr);
524
+
525
+ int result10 = book2.getIsbn().indexOf(gStr);
526
+
527
+ int result11 = book3.getTitle().indexOf(gStr);
528
+
529
+ int result12 = book3.getAuthor().indexOf(gStr);
530
+
531
+ int result13 = book3.getPublisher().indexOf(gStr);
532
+
533
+ int result14 = book3.getYop().indexOf(gStr);
534
+
535
+ int result15 = book3.getIsbn().indexOf(gStr);
536
+
537
+ int result16 = book4.getTitle().indexOf(gStr);
538
+
539
+ int result17 = book4.getAuthor().indexOf(gStr);
540
+
541
+ int result18 = book4.getPublisher().indexOf(gStr);
542
+
543
+ int result19 = book4.getYop().indexOf(gStr);
544
+
545
+ int result20 = book4.getIsbn().indexOf(gStr);
546
+
547
+
548
+
549
+ if (e.getSource() == button1) { //検索ボタン
550
+
551
+ if (result1 != -1 || result2 != -1 || result3 != -1 || result4 != -1 || result5 != -1) {
552
+
553
+ text2.setText(book1.getTitle());
554
+
91
- this.author = author;
555
+ text3.setText(book1.getAuthor());
556
+
557
+ text4.setText(book1.getPublisher());
558
+
559
+ text5.setText(book1.getYop());
560
+
561
+ text6.setText(book1.getIsbn());
562
+
563
+ }
564
+
565
+
566
+
567
+ } else if (e.getSource() == button3) { //進むボタン
568
+
569
+ for (int i = 0; i < 3; i++) {
570
+
571
+ if ((result6 != -1 || result7 != -1 || result8 != -1 || result9 != -1 || result10 != -1) && i == 0) {
572
+
573
+ text2.setText(book2.getTitle());
574
+
575
+ text3.setText(book2.getAuthor());
576
+
577
+ text4.setText(book2.getPublisher());
578
+
579
+ text5.setText(book2.getYop());
580
+
581
+ text6.setText(book2.getIsbn());
582
+
583
+ } else if ((result11 != -1 || result12 != -1 || result13 != -1 || result14 != -1 || result15 != -1)
584
+
585
+ && i == 1) {
586
+
587
+ text2.setText(book3.getTitle());
588
+
589
+ text3.setText(book3.getAuthor());
590
+
591
+ text4.setText(book3.getPublisher());
592
+
593
+ text5.setText(book3.getYop());
594
+
595
+ text6.setText(book3.getIsbn());
596
+
597
+ }
598
+
599
+ }
600
+
601
+ } else if (e.getSource() == button2) { //戻るボタン
602
+
603
+ if ((result11 != -1 || result2 != -1 || result3 != -1 || result4 != -1 || result5 != -1)) {
604
+
605
+ text2.setText(book1.getTitle());
606
+
607
+ text3.setText(book1.getAuthor());
608
+
609
+ text4.setText(book1.getPublisher());
610
+
611
+ text5.setText(book1.getYop());
612
+
613
+ text6.setText(book1.getIsbn());
614
+
615
+ }
616
+
617
+
618
+
619
+ }
92
620
 
93
621
  }
94
622
 
95
-
96
-
97
- public String getPublisher() {
98
-
99
- return publisher;
100
-
101
- }
102
-
103
-
104
-
105
- public void setPublisher(String publisher) {
106
-
107
- this.publisher = publisher;
108
-
109
- }
110
-
111
-
112
-
113
- public String getYop() {
114
-
115
- return yop;
116
-
117
- }
118
-
119
-
120
-
121
- public void setYop(String yop) {
122
-
123
- this.yop = yop;
124
-
125
- }
126
-
127
-
128
-
129
- public String getIsbn() {
130
-
131
- return isbn;
132
-
133
- }
134
-
135
-
136
-
137
- public void setIsbn(String isbn) {
138
-
139
- this.isbn = isbn;
140
-
141
- }
142
-
143
623
  }
144
624
 
145
625
 
146
626
 
147
-
148
-
149
627
  ```
150
628
 
151
- 検索
152
-
153
- ```
154
-
155
- import java.awt.BorderLayout;
156
-
157
- import java.awt.Container;
158
-
159
- import java.awt.GridBagConstraints;
160
-
161
- import java.awt.GridBagLayout;
162
-
163
- import java.awt.Insets;
164
-
165
- import java.awt.event.ActionEvent;
166
-
167
- import java.awt.event.ActionListener;
168
-
169
- import java.io.BufferedReader;
170
-
171
- import java.io.File;
172
-
173
- import java.io.FileReader;
174
-
175
-
176
-
177
- import javax.swing.JButton;
178
-
179
- import javax.swing.JFrame; //フレーム
180
-
181
- import javax.swing.JLabel;
182
-
183
- import javax.swing.JPanel;
184
-
185
- import javax.swing.JTextField;
186
-
187
-
188
-
189
- public class BookData extends JFrame implements ActionListener {
190
-
191
-
192
-
193
- private GridBagLayout grLayout;
194
-
195
- private GridBagConstraints gbc;
196
-
197
- private Container cntnr;
198
-
199
- private JLabel label1, label2, label3, label4, label5, label6, label7;
200
-
201
- private JPanel panel1;
202
-
203
- private JButton button1, button2, button3, button4;
204
-
205
- private JTextField text1, text2, text3, text4, text5, text6;
206
-
207
-
208
-
209
- public String data[][];
210
-
211
-
212
-
213
- // コンストラクタ:窓のタイトル,位置,大きさを設定
214
-
215
- BookData(String title) {
216
-
217
- super(title);
218
-
219
- setBounds(200, 200, 800, 400);
220
-
221
- }
222
-
223
-
224
-
225
- public static void main(String[] args) {
226
-
227
- // TODO 自動生成されたメソッド・スタブ
228
-
229
-
230
-
231
- //自クラスインスタンス生成
232
-
233
- BookData frame;
234
-
235
-
236
-
237
- frame = new BookData("Seach Book"); //タイトル
238
-
239
-
240
-
241
- frame.defineVal(); //表示準備
242
-
243
- frame.setVisible(true); //表示
244
-
245
-
246
-
247
- }
248
-
249
-
250
-
251
- public void readBook() { //csvファイルを読み込み
252
-
253
-
254
-
255
- BufferedReader br = null;
256
-
257
- String read_file = "booklist.csv";
258
-
259
- final int MAX_DATA_NUMS = 100;
260
-
261
- data = new String[MAX_DATA_NUMS][];
262
-
263
- try {
264
-
265
- File file = new File(read_file);
266
-
267
- br = new BufferedReader(new FileReader(file));
268
-
269
-
270
-
271
- int index = 0;
272
-
273
- String line;
274
-
275
- while ((line = br.readLine()) != null) {
276
-
277
- data[index] = line.split(",");
278
-
279
- index++;
280
-
281
- }
282
-
283
- } catch (Exception e) {
284
-
285
- System.out.println(e.getMessage());
286
-
287
- } finally {
288
-
289
- try {
290
-
291
- br.close();
292
-
293
- } catch (Exception e) {
294
-
295
- System.out.println(e.getMessage());
296
-
297
- }
298
-
299
- }
300
-
301
-
302
-
303
- for (int i = 0; i < MAX_DATA_NUMS; i++) {
304
-
305
- if (data[i] == null)
306
-
307
- break;
308
-
309
- for (int j = 0; j < data[i].length; j++) {
310
-
311
- this.data[i][j] = data[i][j]; //配列に格納
312
-
313
- }
314
-
315
- }
316
-
317
- }
318
-
319
-
320
-
321
- private void defineVal() { //レイアウト
322
-
323
-
324
-
325
- cntnr = getContentPane();
326
-
327
- grLayout = new GridBagLayout();
328
-
329
- gbc = new GridBagConstraints();
330
-
331
- panel1 = new JPanel();
332
-
333
- panel1.setLayout(grLayout);
334
-
335
-
336
-
337
- label1 = new JLabel("検索語:");
338
-
339
- label2 = new JLabel("結果:");
340
-
341
- label3 = new JLabel("タイトル:");
342
-
343
- label4 = new JLabel("著者:");
344
-
345
- label5 = new JLabel("出版社:");
346
-
347
- label6 = new JLabel("出版年:");
348
-
349
- label7 = new JLabel("ISBN:");
350
-
351
-
352
-
353
- text1 = new JTextField(50);
354
-
355
- text2 = new JTextField(50);
356
-
357
- text3 = new JTextField(50);
358
-
359
- text4 = new JTextField(50);
360
-
361
- text5 = new JTextField(50);
362
-
363
- text6 = new JTextField(50);
364
-
365
-
366
-
367
- button1 = new JButton("検索");
368
-
369
- button2 = new JButton("<");
370
-
371
- button3 = new JButton(">");
372
-
373
- button4 = new JButton("検索結果保存");
374
-
375
-
376
-
377
- //レイアウト
378
-
379
- gbc.weighty = 0.3d;
380
-
381
-
382
-
383
- gbc.gridx = 0;
384
-
385
- gbc.gridy = 0;
386
-
387
- grLayout.setConstraints(label1, gbc);
388
-
389
-
390
-
391
- gbc.gridx = 1;
392
-
393
- gbc.gridy = 0;
394
-
395
- grLayout.setConstraints(text1, gbc);
396
-
397
-
398
-
399
- gbc.gridx = 2;
400
-
401
- gbc.gridy = 0;
402
-
403
- grLayout.setConstraints(button1, gbc);
404
-
405
-
406
-
407
- gbc.gridx = 0;
408
-
409
- gbc.gridy = 1;
410
-
411
- grLayout.setConstraints(label2, gbc);
412
-
413
-
414
-
415
- gbc.gridx = 0;
416
-
417
- gbc.gridy = 2;
418
-
419
- grLayout.setConstraints(label3, gbc);
420
-
421
-
422
-
423
- gbc.gridx = 1;
424
-
425
- gbc.gridy = 2;
426
-
427
- grLayout.setConstraints(text2, gbc);
428
-
429
-
430
-
431
- gbc.gridx = 0;
432
-
433
- gbc.gridy = 3;
434
-
435
- grLayout.setConstraints(label4, gbc);
436
-
437
-
438
-
439
- gbc.gridx = 1;
440
-
441
- gbc.gridy = 3;
442
-
443
- grLayout.setConstraints(text3, gbc);
444
-
445
-
446
-
447
- gbc.gridx = 0;
448
-
449
- gbc.gridy = 4;
450
-
451
- grLayout.setConstraints(label5, gbc);
452
-
453
-
454
-
455
- gbc.gridx = 1;
456
-
457
- gbc.gridy = 4;
458
-
459
- grLayout.setConstraints(text4, gbc);
460
-
461
-
462
-
463
- gbc.gridx = 0;
464
-
465
- gbc.gridy = 5;
466
-
467
- grLayout.setConstraints(label6, gbc);
468
-
469
-
470
-
471
- gbc.gridx = 1;
472
-
473
- gbc.gridy = 5;
474
-
475
- grLayout.setConstraints(text5, gbc);
476
-
477
-
478
-
479
- gbc.gridx = 0;
480
-
481
- gbc.gridy = 6;
482
-
483
- grLayout.setConstraints(label7, gbc);
484
-
485
-
486
-
487
- gbc.gridx = 1;
488
-
489
- gbc.gridy = 6;
490
-
491
- grLayout.setConstraints(text6, gbc);
492
-
493
-
494
-
495
- gbc.gridx = 1;
496
-
497
- gbc.gridy = 7;
498
-
499
- gbc.anchor = GridBagConstraints.WEST;
500
-
501
- gbc.insets = new Insets(0, 150, 0, 0);
502
-
503
- grLayout.setConstraints(button2, gbc);
504
-
505
-
506
-
507
- gbc.gridx = 1;
508
-
509
- gbc.gridy = 7;
510
-
511
- gbc.anchor = GridBagConstraints.CENTER;
512
-
513
- gbc.insets = new Insets(0, 0, 0, 0);
514
-
515
- grLayout.setConstraints(button3, gbc);
516
-
517
-
518
-
519
- gbc.gridx = 1;
520
-
521
- gbc.gridy = 7;
522
-
523
- gbc.anchor = GridBagConstraints.EAST;
524
-
525
- gbc.insets = new Insets(0, 0, 0, 50);
526
-
527
- grLayout.setConstraints(button4, gbc);
528
-
529
-
530
-
531
- panel1.add(label1);
532
-
533
- panel1.add(label2);
534
-
535
- panel1.add(label3);
536
-
537
- panel1.add(label4);
538
-
539
- panel1.add(label5);
540
-
541
- panel1.add(label6);
542
-
543
- panel1.add(label7);
544
-
545
-
546
-
547
- panel1.add(text1);
548
-
549
- panel1.add(text2);
550
-
551
- panel1.add(text3);
552
-
553
- panel1.add(text4);
554
-
555
- panel1.add(text5);
556
-
557
- panel1.add(text6);
558
-
559
-
560
-
561
- panel1.add(button1);
562
-
563
- panel1.add(button2);
564
-
565
- panel1.add(button3);
566
-
567
- panel1.add(button4);
568
-
569
-
570
-
571
- cntnr.add(panel1, BorderLayout.CENTER);
572
-
573
-
574
-
575
- button1.addActionListener(this);
576
-
577
- button2.addActionListener(this);
578
-
579
- button3.addActionListener(this);
580
-
581
- button4.addActionListener(this);
582
-
583
-
584
-
585
- //窓を閉じたとき、プログラム終了
586
-
587
- setDefaultCloseOperation(EXIT_ON_CLOSE);
588
-
589
-
590
-
591
- }
592
-
593
-
594
-
595
- @Override
596
-
597
- public void actionPerformed(ActionEvent e) {
598
-
599
- // TODO 自動生成されたメソッド・スタブ
600
-
601
-
602
-
603
- readBook();
604
-
605
-
606
-
607
- //オブジェクト型の配列生成
608
-
609
- Book bk[] = new Book[4];
610
-
611
- bk[0] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
612
-
613
- bk[1] = new Book(data[1][0], data[1][1], data[1][2], data[1][3], data[1][4]);
614
-
615
- bk[2] = new Book(data[2][0], data[2][1], data[2][2], data[2][3], data[2][4]);
616
-
617
- bk[3] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
618
-
619
-
620
-
621
- //検索文字列を取得
622
-
623
- String gStr = text1.getText();
624
-
625
-
626
-
627
- //部分文字列検索
628
-
629
- int result1 = book1.getTitle().indexOf(gStr);
630
-
631
- int result2 = book1.getAuthor().indexOf(gStr);
632
-
633
- int result3 = book1.getPublisher().indexOf(gStr);
634
-
635
- int result4 = book1.getYop().indexOf(gStr);
636
-
637
- int result5 = book1.getIsbn().indexOf(gStr);
638
-
639
- int result6 = book2.getTitle().indexOf(gStr);
640
-
641
- int result7 = book2.getAuthor().indexOf(gStr);
642
-
643
- int result8 = book2.getPublisher().indexOf(gStr);
644
-
645
- int result9 = book2.getYop().indexOf(gStr);
646
-
647
- int result10 = book2.getIsbn().indexOf(gStr);
648
-
649
- int result11 = book3.getTitle().indexOf(gStr);
650
-
651
- int result12 = book3.getAuthor().indexOf(gStr);
652
-
653
- int result13 = book3.getPublisher().indexOf(gStr);
654
-
655
- int result14 = book3.getYop().indexOf(gStr);
656
-
657
- int result15 = book3.getIsbn().indexOf(gStr);
658
-
659
- int result16 = book4.getTitle().indexOf(gStr);
660
-
661
- int result17 = book4.getAuthor().indexOf(gStr);
662
-
663
- int result18 = book4.getPublisher().indexOf(gStr);
664
-
665
- int result19 = book4.getYop().indexOf(gStr);
666
-
667
- int result20 = book4.getIsbn().indexOf(gStr);
668
-
669
-
670
-
671
- if (e.getSource() == button1) { //検索ボタン
672
-
673
- if (result1 != -1 || result2 != -1 || result3 != -1 || result4 != -1 || result5 != -1) {
674
-
675
- text2.setText(book1.getTitle());
676
-
677
- text3.setText(book1.getAuthor());
678
-
679
- text4.setText(book1.getPublisher());
680
-
681
- text5.setText(book1.getYop());
682
-
683
- text6.setText(book1.getIsbn());
684
-
685
- }
686
-
687
-
688
-
689
- } else if (e.getSource() == button3) { //進むボタン
690
-
691
- for (int i = 0; i < 3; i++) {
692
-
693
- if ((result6 != -1 || result7 != -1 || result8 != -1 || result9 != -1 || result10 != -1) && i == 0) {
694
-
695
- text2.setText(book2.getTitle());
696
-
697
- text3.setText(book2.getAuthor());
698
-
699
- text4.setText(book2.getPublisher());
700
-
701
- text5.setText(book2.getYop());
702
-
703
- text6.setText(book2.getIsbn());
704
-
705
- } else if ((result11 != -1 || result12 != -1 || result13 != -1 || result14 != -1 || result15 != -1)
706
-
707
- && i == 1) {
708
-
709
- text2.setText(book3.getTitle());
710
-
711
- text3.setText(book3.getAuthor());
712
-
713
- text4.setText(book3.getPublisher());
714
-
715
- text5.setText(book3.getYop());
716
-
717
- text6.setText(book3.getIsbn());
718
-
719
- }
720
-
721
- }
722
-
723
- } else if (e.getSource() == button2) { //戻るボタン
724
-
725
- if ((result11 != -1 || result2 != -1 || result3 != -1 || result4 != -1 || result5 != -1)) {
726
-
727
- text2.setText(book1.getTitle());
728
-
729
- text3.setText(book1.getAuthor());
730
-
731
- text4.setText(book1.getPublisher());
732
-
733
- text5.setText(book1.getYop());
734
-
735
- text6.setText(book1.getIsbn());
736
-
737
- }
738
-
739
-
740
-
741
- }
742
-
743
- }
744
-
745
- }
746
-
747
-
748
-
749
- ```
750
-
751
629
 
752
630
 
753
631
  ### 試したこと
754
632
 
755
633
 
756
634
 
757
- if分でどうにかやろうと思いましたが全くできませんでした。
758
-
759
- 助けてください。
760
-
761
-
762
-
763
635
  ### 補足情報(FW/ツールのバージョンなど)
764
-
765
-
766
-
767
- csvファイルの蔵書データを読み込みます。
768
-
769
- eclipse
770
-
771
- swing

2

コード書き換え

2021/07/21 16:49

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -604,15 +604,17 @@
604
604
 
605
605
 
606
606
 
607
- //インスタンス生成
607
+ //オブジェクト型の配列生成
608
+
608
-
609
+ Book bk[] = new Book[4];
610
+
609
- Book book1 = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
611
+ bk[0] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
610
-
612
+
611
- Book book2 = new Book(data[1][0], data[1][1], data[1][2], data[1][3], data[1][4]);
613
+ bk[1] = new Book(data[1][0], data[1][1], data[1][2], data[1][3], data[1][4]);
612
-
614
+
613
- Book book3 = new Book(data[2][0], data[2][1], data[2][2], data[2][3], data[2][4]);
615
+ bk[2] = new Book(data[2][0], data[2][1], data[2][2], data[2][3], data[2][4]);
614
-
616
+
615
- Book book4 = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
617
+ bk[3] = new Book(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4]);
616
618
 
617
619
 
618
620
 

1

題名を変えました

2021/07/21 03:38

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- Java ボタンで前後に移動する方法
1
+ Java ボタンでページめくる方法
test CHANGED
File without changes