My program, gives me a list of files in a directory. This directory is accessed via a txt file. In the second line of the txt file I would now write numbers. For a "1" the file with the "exersice-1" and the current date should be displayed in the xy-graph. Simultaneously the same with the "2". Someone an idea where the error is?
The Output of the Files:
export_test_practise-1_2017-06-23_2017-06-23.csv
export_test_practise-1_2017-06-24_2017-06-24.csv
export_test_practise-2_2017-06-24_2017-06-24.csv
My Code:
public class Test {
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
ApplicationFrame frame = new ApplicationFrame("Temperaturprofile");
Test test = new Test();
try {
frame.add(test.createChart("Temperature profile"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
frame.pack();
frame.setLocationRelativeTo(null);;
frame.setVisible(true);
});
}
private ChartPanel createChart(String chartTitle) throws IOException {
JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle,
"Time", "Temperature", createDataset(), true, true, false);
ChartPanel chartPanel = new ChartPanel(chart);
XYPlot plot = chart.getXYPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ssX");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
axis.setDateFormatOverride(df.getTimeInstance());
plot.setBackgroundPaint(Color.WHITE);
return chartPanel;
}
public XYDataset createDataset() throws IOException {
TimeSeries series = new TimeSeries("Temperature");
TimeSeriesCollection dataset = new TimeSeriesCollection(series);
File dir = new File("../User/Test.txt");
// Read from the file
BufferedReader br = new BufferedReader(new FileReader(dir));
String line = br.readLine();
String path2 = br.readLine();
br.close();
new File (line);
File[] fileList = new File (line).listFiles(new FilenameFilter() {
//Nur Dateien mit .csv Endung werden zurückgegeben
public boolean accept(File dir, String name) {
return name.endsWith(".csv");
}
});
for (File f : fileList){
Arrays.sort(fileList);
System.out.println(f.getName());
}
long mod = 0;
File found;
if (path2.equals(1))
if (dir.isFile() && dir.getName().toLowerCase().endsWith("1") && dir.lastModified() > mod){
mod = dir.lastModified();
found = dir;
}
else if (path2.equals(2))
if (dir.isFile() && dir.getName().toLowerCase().endsWith("2") && dir.lastModified() > mod){
mod = dir.lastModified();
found = dir;
}
return dataset;
}
}
Aucun commentaire:
Enregistrer un commentaire