I'm writing a program which will read, record, and plot modbus values on a time series. I have everything figured out aside from the plotting part. My issue lies with the GUI. I am trying to set up the GUI such that I have several tabbed panes, with a plotted chart on the inside of a tabbed pane with a "Plot" button to trigger the actual plotting method. I am using JFreePlot.
My current code for the program is shown below, but it's not really complete, so to be precise I am just wondering as to how I can place a JFreeChart in a "space" in a tabbed pane in a JFrame, activated by a button within the same tabbed pane as the chart.
private class SwingAction_5 extends AbstractAction {
public SwingAction_5() {
putValue(NAME, "SwingAction_5");
putValue(SHORT_DESCRIPTION, "Some short description");
}
public void actionPerformed(ActionEvent e) {
try{
JFrame frame = new JFrame();
FileDialog fd = new FileDialog(frame,"Choose a file",FileDialog.LOAD);
fd.setDirectory("C:\\");
fd.setFile("*.txt");
fd.setVisible(true);
String f_name = fd.getFile();
BufferedReader reader = new BufferedReader(new FileReader(f_name));
int lines = 0;
while (reader.readLine() != null) {lines++;}
reader.close();
FileInputStream fis = new FileInputStream(f_name);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line=null;
Float[] f_arr = new Float[lines];
for(int i=0;i<lines;i++){
f_arr[i] = Float.parseFloat(br.readLine());
}
br.close();
final XYSeries series = new XYSeries("Data");
for (int i = 0; i < f_arr[0]*f_arr[1]; i++) {
series.add(i, f_arr[i+2]);
}
XYSeriesCollection dataset = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createXYLineChart("Amperage Deviation", "Seconds","Amps", dataset, PlotOrientation.VERTICAL, false, false, false);
JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final JTabbedPane jtp = new JTabbedPane();
jtp.add(jtp, BorderLayout.CENTER);
frame.add(p,BorderLayout.SOUTH);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
catch(Exception mbi){
mbi.printStackTrace();
System.exit(1);
}
}
}