|
| 1 | +import javax.swing.JFrame; |
| 2 | + |
1 | 3 | import java.awt.BorderLayout;
|
2 | 4 | import java.awt.FlowLayout;
|
3 |
| - |
4 |
| -import javax.swing.BoxLayout; |
5 |
| -import javax.swing.JButton; |
6 |
| -import javax.swing.JFrame; |
| 5 | +import java.awt.GridLayout; |
| 6 | +import javax.swing.JLabel; |
7 | 7 | import javax.swing.JPanel;
|
| 8 | +import javax.swing.JTextField; |
| 9 | +import javax.swing.JButton; |
| 10 | +import org.jfree.chart.ChartFactory; |
| 11 | +import org.jfree.chart.ChartPanel; |
| 12 | +import org.jfree.chart.JFreeChart; |
| 13 | +import org.jfree.chart.plot.PlotOrientation; |
| 14 | +import org.jfree.data.xy.XYSeries; |
| 15 | +import org.jfree.data.xy.XYSeriesCollection; |
8 | 16 |
|
9 | 17 | public class Window extends JFrame
|
10 | 18 | {
|
11 | 19 | private static final long serialVersionUID = 1L;
|
12 |
| - protected JButton btn_server_init; |
13 |
| - protected JButton btn_server_stop; |
| 20 | + final XYSeries dataLogged; |
| 21 | + final XYSeriesCollection collectionData; |
| 22 | + final JFreeChart display; |
| 23 | + public JTextField txt_port; |
| 24 | + public JTextField txt_acq_time; |
| 25 | + public JTextField txt_sample_time; |
| 26 | + public JTextField txt_step_time; |
| 27 | + public JTextField txt_file_name; |
| 28 | + public JButton btn_server_init; |
| 29 | + public JButton btn_server_stop; |
14 | 30 |
|
15 | 31 | public Window()
|
16 | 32 | {
|
17 |
| - this.setTitle("Simple Server"); |
18 |
| - this.setBounds(200,200,300,200); |
19 |
| - this.setDefaultCloseOperation(EXIT_ON_CLOSE); |
| 33 | + this.setTitle("Real Time Control App"); |
| 34 | + this.setBounds(300,440,500,300); |
| 35 | + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 36 | + JPanel mainPanel = new JPanel(); |
| 37 | + mainPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
20 | 38 |
|
21 |
| - JPanel main = new JPanel(); |
22 |
| - main.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
23 |
| - btn_server_init = new JButton("Iniciar Servidor"); |
24 |
| - btn_server_stop = new JButton("Detener Servidor"); |
| 39 | + /*Parameters panel*/ |
| 40 | + JPanel parametersPanel = new JPanel(); |
| 41 | + JLabel lbl_param_1 = new JLabel("Port Number"); |
| 42 | + JLabel lbl_param_2 = new JLabel("Acquisition Time (s)"); |
| 43 | + JLabel lbl_param_3 = new JLabel("Sample Time (s)"); |
| 44 | + JLabel lbl_param_4 = new JLabel("Step Time (s)"); |
| 45 | + JLabel lbl_param_5 = new JLabel("File Name"); |
| 46 | + txt_port = new JTextField("16"); |
| 47 | + txt_acq_time = new JTextField(""); |
| 48 | + txt_sample_time = new JTextField("0.5"); |
| 49 | + txt_step_time = new JTextField("15"); |
| 50 | + txt_file_name = new JTextField(""); |
| 51 | + txt_port.setHorizontalAlignment(JTextField.CENTER); |
| 52 | + txt_acq_time.setHorizontalAlignment(JTextField.CENTER); |
| 53 | + txt_sample_time.setHorizontalAlignment(JTextField.CENTER); |
| 54 | + txt_step_time.setHorizontalAlignment(JTextField.CENTER); |
| 55 | + txt_file_name.setHorizontalAlignment(JTextField.CENTER); |
| 56 | + btn_server_init = new JButton("Start Acquisition"); |
| 57 | + btn_server_stop = new JButton("Save Data"); |
25 | 58 | btn_server_init.setActionCommand("start");
|
26 | 59 | btn_server_stop.setActionCommand("stop");
|
27 |
| - JPanel container = new JPanel(); |
28 |
| - container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS)); |
29 |
| - container.add(btn_server_init); |
30 |
| - container.add(btn_server_stop); |
31 |
| - main.add(container); |
32 |
| - this.getContentPane().add(main, BorderLayout.CENTER); |
| 60 | + parametersPanel.setLayout(new GridLayout(6, 2,10,10)); |
| 61 | + parametersPanel.add(lbl_param_1); |
| 62 | + parametersPanel.add(txt_port); |
| 63 | + parametersPanel.add(lbl_param_2); |
| 64 | + parametersPanel.add(txt_acq_time); |
| 65 | + parametersPanel.add(lbl_param_3); |
| 66 | + parametersPanel.add(txt_sample_time); |
| 67 | + parametersPanel.add(lbl_param_4); |
| 68 | + parametersPanel.add(txt_step_time); |
| 69 | + parametersPanel.add(lbl_param_5); |
| 70 | + parametersPanel.add(txt_file_name); |
| 71 | + parametersPanel.add(btn_server_init); |
| 72 | + parametersPanel.add(btn_server_stop); |
| 73 | + mainPanel.add(parametersPanel, BorderLayout.EAST); |
| 74 | + this.getContentPane().add(mainPanel, BorderLayout.EAST); |
| 75 | + |
| 76 | + // Setup the Chart panel |
| 77 | + dataLogged = new XYSeries("Proocess Dynamics"); |
| 78 | + dataLogged.add(0,0); |
| 79 | + collectionData = new XYSeriesCollection(); |
| 80 | + collectionData.addSeries(dataLogged); |
| 81 | + display = ChartFactory.createXYLineChart("Realtime Plant Output", |
| 82 | + "Time", |
| 83 | + "Amplitude", |
| 84 | + collectionData, |
| 85 | + PlotOrientation.VERTICAL, |
| 86 | + true, |
| 87 | + true, |
| 88 | + false); |
| 89 | + JPanel rt_panel = new ChartPanel(display); |
| 90 | + this.getContentPane().add(rt_panel, BorderLayout.CENTER); |
33 | 91 | this.setVisible(true);
|
34 | 92 | }
|
35 | 93 | }
|
0 commit comments