もう一つ追加したクラスは、JAVAのGUI機能を組み込んで、自由にタイムスタンプ付きのイベントやコメントを記載できるようにしておいた。
setup()関数内で以下のように宣言すればよい。テキストボックに書き込んだ内容は、saveボタンで、user_dataフォルダ内のidフォルダ内にdata_info.txtとして保存される。また、タイムスタンプボタンを押せば、現在時刻がテキストフィールドに追加できるようにしておいた。
1 |
new MyFrame().setVisible(true); |
—————————————————————-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
String date_now, time_now, time_now2, date, start_time; PrintWriter output5; public class MyFrame extends javax.swing.JFrame implements ActionListener { private final JSplitPane splitPane; private final JPanel topPanel; private final JPanel bottomPanel; private final JScrollPane scrollPane; private final JTextArea textArea; private final JPanel inputPanel; private final JButton button1; private final JButton button2; String data_info; public MyFrame() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - this.getWidth()-400; int y = 0; this.setLocation(x, y); this.setVisible(true); splitPane = new JSplitPane(); topPanel = new JPanel(); bottomPanel = new JPanel(); scrollPane = new JScrollPane(); textArea = new JTextArea(); inputPanel = new JPanel(); button1 = new JButton("save"); button2= new JButton("Time Stamp"); setPreferredSize(new Dimension(400, 400)); getContentPane().setLayout(new GridLayout()); getContentPane().add(splitPane); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); splitPane.setDividerLocation(50); splitPane.setTopComponent(topPanel); splitPane.setBottomComponent(bottomPanel); bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS)); bottomPanel.add(scrollPane); scrollPane.setViewportView(textArea); bottomPanel.add(inputPanel); inputPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 75)); inputPanel.setLayout(new BoxLayout(inputPanel, BoxLayout.X_AXIS)); inputPanel.add(button1); inputPanel.add(button2); button1.addActionListener(this); button2.addActionListener(this); pack(); } public void actionPerformed(ActionEvent e) { if (e.getSource()==button1) { data_info = textArea.getText(); println("data_info=", data_info); save_input_text(data_info); } if (e.getSource()==button2) { year = year(); month = month(); day = day(); sec = second(); min = minute(); hour = hour(); date = year + ":" + nf(month, 2) + ":" + nf(day, 2); time = nf(hour, 2) + ":" + nf(min, 2) + ":" + nf(sec, 2); println("time stamp:= @"+date+": "+time+":"); textArea.append("@"+date+": "+time+":"); } } public void save_input_text(String _data_info) { year = year(); month = month(); day = day(); sec = second(); min = minute(); hour = hour(); date = year + ":" + nf(month, 2) + ":" + nf(day, 2); time = nf(hour, 2) + ":" + nf(min, 2) + ":" + nf(sec, 2); output5 = createWriter("user_data/" + global_id + "/data_info.txt"); output5.println("saved: @ "+date + ": "+time); output5.println(_data_info); println("data_info=", _data_info); output5.flush(); textArea.append("Saved @"+date+": "+time+":"); } } |