class SelectDateのテキストボックスに入力された値(日付)を
class SeePastの左上に表示させたいと思っています。(現在はaaaを表示させています)
表示のさせ方を教えていただけますと幸いです。
よろしくお願いいたします。
Java
1//SelectDateクラス 2 3package swing_test; 4 5import java.awt.BorderLayout; 6import java.awt.Component; 7import java.awt.EventQueue; 8import java.awt.Window; 9import java.awt.event.ActionEvent; 10import java.awt.event.ActionListener; 11 12import javax.swing.JFrame; 13import javax.swing.JPanel; 14import javax.swing.SwingConstants; 15import javax.swing.SwingUtilities; 16import javax.swing.border.EmptyBorder; 17import javax.swing.JLabel; 18import javax.swing.JTextField; 19import javax.swing.JButton; 20 21public class SelectDate extends JFrame { 22 23 private JPanel contentPane; 24 private JTextField txtDate; 25 26 /** 27 * Launch the application. 28 */ 29 public static void main(String[] args) { 30 EventQueue.invokeLater(new Runnable() { 31 public void run() { 32 try { 33 SelectDate frame = new SelectDate(); 34 frame.setVisible(true); 35 } catch (Exception e) { 36 e.printStackTrace(); 37 } 38 } 39 }); 40 } 41 42 /** 43 * Create the frame. 44 */ 45 public SelectDate() { 46 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 47 setBounds(500, 250, 450, 300); 48 contentPane = new JPanel(); 49 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 50 setContentPane(contentPane); 51 contentPane.setLayout(null); 52 53 JLabel lblDate = new JLabel("日付を選択", SwingConstants.RIGHT); 54 lblDate.setBounds(118, 65, 98, 32); 55 contentPane.add(lblDate); 56 57 txtDate = new JTextField(); 58 txtDate.setBounds(236, 68, 130, 26); 59 contentPane.add(txtDate); 60 txtDate.setColumns(10); 61 //txtDateの値を取り出す 62 String txtdata = txtDate.getText(); 63 64 JButton btnSearch = new JButton("検索"); 65 btnSearch.setBounds(236, 120, 117, 29); 66 contentPane.add(btnSearch); 67 68 //ボタン押下時(past) 69 btnSearch.addActionListener(new ActionListener() { 70 public void actionPerformed(ActionEvent e) { 71 SeePast.main(null); 72 //ウィンドウを閉じる 73 Component c = (Component)e.getSource(); 74 Window w = SwingUtilities.getWindowAncestor(c); 75 w.dispose(); 76 } 77 78 }); 79 } 80} 81
Java
1//SeePastクラス 2package swing_test; 3 4import java.awt.BorderLayout; 5import java.awt.EventQueue; 6 7import javax.swing.JFrame; 8import javax.swing.JPanel; 9import javax.swing.SwingConstants; 10import javax.swing.border.EmptyBorder; 11import javax.swing.JLabel; 12 13public class SeePast extends JFrame { 14 15 private JPanel contentPane; 16 17 /** 18 * Launch the application. 19 */ 20 public static void main(String[] args) { 21 EventQueue.invokeLater(new Runnable() { 22 public void run() { 23 try { 24 SeePast frame = new SeePast(); 25 frame.setVisible(true); 26 } catch (Exception e) { 27 e.printStackTrace(); 28 } 29 } 30 }); 31 } 32 33 /** 34 * Create the frame. 35 */ 36 public SeePast() { 37 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 38 setBounds(500, 250, 450, 300); 39 contentPane = new JPanel(); 40 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 41 setContentPane(contentPane); 42 contentPane.setLayout(null); 43 44 String lbl = "aaa"; 45 JLabel lblSelectDate = new JLabel(lbl); 46 lblSelectDate.setBounds(60, 35, 61, 16); 47 contentPane.add(lblSelectDate); 48 49 JLabel lblContents = new JLabel("学習内容", SwingConstants.RIGHT); 50 lblContents.setBounds(60, 99, 61, 16); 51 contentPane.add(lblContents); 52 53 JLabel lblFeel = new JLabel("感想", SwingConstants.RIGHT); 54 lblFeel.setBounds(60, 147, 61, 16); 55 contentPane.add(lblFeel); 56 57 JLabel lbljava = new JLabel("(例)Java"); 58 lbljava.setBounds(182, 99, 119, 16); 59 contentPane.add(lbljava); 60 61 JLabel lblUnderstand = new JLabel("(例)理解できた"); 62 lblUnderstand.setBounds(182, 147, 150, 16); 63 contentPane.add(lblUnderstand); 64 } 65 66} 67
ご質問に付けられた textbox タグは HTML ですので件とは関係ありません.
外されたほうが宜しいかと思います.
回答2件
あなたの回答
tips
プレビュー