回答編集履歴

1

追記(変更最小)

2019/12/29 06:25

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -229,3 +229,277 @@
229
229
  日付を選択し指定日のメモ等が新たにウィンドウを出すということだと思いますが、SelectDateは閉じちゃっていいんでしょうか?
230
230
 
231
231
  戻れなくなってしまいそうですが。
232
+
233
+
234
+
235
+ ---
236
+
237
+
238
+
239
+ 追記(変更最小)
240
+
241
+
242
+
243
+ ```Java
244
+
245
+ import java.awt.Component;
246
+
247
+ import java.awt.EventQueue;
248
+
249
+ import java.awt.Window;
250
+
251
+ import java.awt.event.ActionEvent;
252
+
253
+ import java.awt.event.ActionListener;
254
+
255
+ import javax.swing.JButton;
256
+
257
+ import javax.swing.JFrame;
258
+
259
+ import javax.swing.JLabel;
260
+
261
+ import javax.swing.JPanel;
262
+
263
+ import javax.swing.JTextField;
264
+
265
+ import javax.swing.SwingConstants;
266
+
267
+ import javax.swing.SwingUtilities;
268
+
269
+ import javax.swing.border.EmptyBorder;
270
+
271
+
272
+
273
+ public class SelectDate extends JFrame {
274
+
275
+
276
+
277
+ private JPanel contentPane;
278
+
279
+ private JTextField txtDate;
280
+
281
+
282
+
283
+ /**
284
+
285
+ * Launch the application.
286
+
287
+ */
288
+
289
+ public static void main(String[] args) {
290
+
291
+ EventQueue.invokeLater(new Runnable() {
292
+
293
+ public void run() {
294
+
295
+ try {
296
+
297
+ SelectDate frame = new SelectDate();
298
+
299
+ frame.setVisible(true);
300
+
301
+ } catch (Exception e) {
302
+
303
+ e.printStackTrace();
304
+
305
+ }
306
+
307
+ }
308
+
309
+ });
310
+
311
+ }
312
+
313
+
314
+
315
+ /**
316
+
317
+ * Create the frame.
318
+
319
+ */
320
+
321
+ public SelectDate() {
322
+
323
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
324
+
325
+ setBounds(500, 250, 450, 300);
326
+
327
+ contentPane = new JPanel();
328
+
329
+ contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
330
+
331
+ setContentPane(contentPane);
332
+
333
+ contentPane.setLayout(null);
334
+
335
+
336
+
337
+ JLabel lblDate = new JLabel("日付を選択", SwingConstants.RIGHT);
338
+
339
+ lblDate.setBounds(118, 65, 98, 32);
340
+
341
+ contentPane.add(lblDate);
342
+
343
+
344
+
345
+ txtDate = new JTextField();
346
+
347
+ txtDate.setBounds(236, 68, 130, 26);
348
+
349
+ contentPane.add(txtDate);
350
+
351
+ txtDate.setColumns(10);
352
+
353
+ //txtDateの値を取り出す
354
+
355
+ String txtdata = txtDate.getText();
356
+
357
+
358
+
359
+ JButton btnSearch = new JButton("検索");
360
+
361
+ btnSearch.setBounds(236, 120, 117, 29);
362
+
363
+ contentPane.add(btnSearch);
364
+
365
+
366
+
367
+ //ボタン押下時(past)
368
+
369
+ btnSearch.addActionListener(new ActionListener() {
370
+
371
+ public void actionPerformed(ActionEvent e) {
372
+
373
+ String txtdata = txtDate.getText();
374
+
375
+ SeePast frame = new SeePast(txtdata);
376
+
377
+ frame.setVisible(true);
378
+
379
+ //ウィンドウを閉じる
380
+
381
+ Component c = (Component) e.getSource();
382
+
383
+ Window w = SwingUtilities.getWindowAncestor(c);
384
+
385
+ w.dispose();
386
+
387
+ }
388
+
389
+
390
+
391
+ });
392
+
393
+ }
394
+
395
+ }
396
+
397
+
398
+
399
+ class SeePast extends JFrame {
400
+
401
+
402
+
403
+ private JPanel contentPane;
404
+
405
+
406
+
407
+ /**
408
+
409
+ * Launch the application.
410
+
411
+ */
412
+
413
+ public static void main(String[] args) {
414
+
415
+ EventQueue.invokeLater(new Runnable() {
416
+
417
+ public void run() {
418
+
419
+ try {
420
+
421
+ SeePast frame = new SeePast("aaa");
422
+
423
+ frame.setVisible(true);
424
+
425
+ } catch (Exception e) {
426
+
427
+ e.printStackTrace();
428
+
429
+ }
430
+
431
+ }
432
+
433
+ });
434
+
435
+ }
436
+
437
+
438
+
439
+ /**
440
+
441
+ * Create the frame.
442
+
443
+ */
444
+
445
+ public SeePast(String str) {
446
+
447
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
448
+
449
+ setBounds(500, 250, 450, 300);
450
+
451
+ contentPane = new JPanel();
452
+
453
+ contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
454
+
455
+ setContentPane(contentPane);
456
+
457
+ contentPane.setLayout(null);
458
+
459
+
460
+
461
+ String lbl = str;
462
+
463
+ JLabel lblSelectDate = new JLabel(lbl);
464
+
465
+ lblSelectDate.setBounds(60, 35, 61, 16);
466
+
467
+ contentPane.add(lblSelectDate);
468
+
469
+
470
+
471
+ JLabel lblContents = new JLabel("学習内容", SwingConstants.RIGHT);
472
+
473
+ lblContents.setBounds(60, 99, 61, 16);
474
+
475
+ contentPane.add(lblContents);
476
+
477
+
478
+
479
+ JLabel lblFeel = new JLabel("感想", SwingConstants.RIGHT);
480
+
481
+ lblFeel.setBounds(60, 147, 61, 16);
482
+
483
+ contentPane.add(lblFeel);
484
+
485
+
486
+
487
+ JLabel lbljava = new JLabel("(例)Java");
488
+
489
+ lbljava.setBounds(182, 99, 119, 16);
490
+
491
+ contentPane.add(lbljava);
492
+
493
+
494
+
495
+ JLabel lblUnderstand = new JLabel("(例)理解できた");
496
+
497
+ lblUnderstand.setBounds(182, 147, 150, 16);
498
+
499
+ contentPane.add(lblUnderstand);
500
+
501
+ }
502
+
503
+ }
504
+
505
+ ```