我试图在一秒钟之后从两个点显示一组行。但是当我运行如下所示的代码时...我得到一组最初为空的JFrame。只有当“for”时循环完成后,我看到这些帧上的数据。如果每个帧都单独显示给用户,请你帮我解决如何在帧上显示数据...提前感谢。
public class XYLineChartExample extends JFrame {
static ChartPanel panel ;
static JFreeChart chart;
public XYLineChartExample(String title,int i) throws InterruptedException {
super(title);
XYDataset dataset = createDataset(i);
// Create chart
chart = ChartFactory.createXYLineChart(
"XY Line Chart Example",
"X-Axis",
"Y-Axis",
dataset,
PlotOrientation.VERTICAL,
true, true, false);
// Create Panel
panel = new ChartPanel(chart);
setContentPane(panel);
}
private XYDataset createDataset(int i) {
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries series = new XYSeries("Y = X + 2");
series.add(i,i+2 );
series.add(i+3,i+5 );
//Add series to dataset
dataset.addSeries(series);
return dataset;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
for(int i=1;i<5;i++){
try {
XYLineChartExample example;
example = new XYLineChartExample("XY Chart Example",i);
example.setSize(1000, 600);
example.setLocationRelativeTo(null);
example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
example.setVisible(true);
Thread.sleep(2000);
// panel.removeAll();
// panel.add(example);
// panel.updateUI();
// example.removeAll();
// example.add(chart);
// example.dispose();
} catch (InterruptedException ex) {
Logger.getLogger(XYLineChartExample.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
}