1 37 package org.jfree.chart.demo; 38 39 import java.awt.Dimension ; 40 41 import javax.swing.JDesktopPane ; 42 import javax.swing.JInternalFrame ; 43 44 import org.jfree.chart.ChartFactory; 45 import org.jfree.chart.ChartPanel; 46 import org.jfree.chart.JFreeChart; 47 import org.jfree.chart.plot.PlotOrientation; 48 import org.jfree.data.DefaultCategoryDataset; 49 import org.jfree.data.XYDataset; 50 import org.jfree.data.time.Minute; 51 import org.jfree.data.time.RegularTimePeriod; 52 import org.jfree.data.time.TimeSeries; 53 import org.jfree.data.time.TimeSeriesCollection; 54 import org.jfree.ui.ApplicationFrame; 55 import org.jfree.ui.RefineryUtilities; 56 57 62 public class InternalFrameDemo extends ApplicationFrame { 63 64 69 public InternalFrameDemo(String title) { 70 super(title); 71 JDesktopPane desktopPane = new JDesktopPane (); 72 desktopPane.setPreferredSize(new Dimension (600, 400)); 73 JInternalFrame frame1 = createFrame1(); 74 desktopPane.add(frame1); 75 frame1.pack(); 76 frame1.setVisible(true); 77 JInternalFrame frame2 = createFrame2(); 78 desktopPane.add(frame2); 79 frame2.pack(); 80 frame2.setLocation(100, 200); 81 frame2.setVisible(true); 82 getContentPane().add(desktopPane); 83 } 84 85 90 private JInternalFrame createFrame1() { 91 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 92 dataset.addValue(34.0, "Series 1", "Category 1"); 93 dataset.addValue(23.0, "Series 1", "Category 2"); 94 dataset.addValue(54.0, "Series 1", "Category 3"); 95 JFreeChart chart = ChartFactory.createBarChart( 96 "Bar Chart", 97 "Category", 98 "Series", 99 dataset, 100 PlotOrientation.VERTICAL, 101 true, 102 true, 103 false 104 ); 105 ChartPanel chartPanel = new ChartPanel(chart); 106 chartPanel.setPreferredSize(new Dimension (200, 100)); 107 JInternalFrame frame = new JInternalFrame ("Frame 1", true); 108 frame.getContentPane().add(chartPanel); 109 return frame; 110 111 } 112 113 118 private JInternalFrame createFrame2() { 119 XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); 120 121 JFreeChart chart = ChartFactory.createTimeSeriesChart( 122 "Time Series Chart", 123 "Time of Day", 124 "Value", 125 dataset1, 126 true, 127 true, 128 false 129 ); 130 ChartPanel chartPanel = new ChartPanel(chart); 131 chartPanel.setPreferredSize(new Dimension (200, 100)); 132 JInternalFrame frame = new JInternalFrame ("Frame 2", true); 133 frame.getContentPane().add(chartPanel); 134 return frame; 135 } 136 137 147 private XYDataset createDataset(String name, double base, RegularTimePeriod start, int count) { 148 149 TimeSeries series = new TimeSeries(name, start.getClass()); 150 RegularTimePeriod period = start; 151 double value = base; 152 for (int i = 0; i < count; i++) { 153 series.add(period, value); 154 period = period.next(); 155 value = value * (1 + (Math.random() - 0.495) / 10.0); 156 } 157 158 TimeSeriesCollection dataset = new TimeSeriesCollection(); 159 dataset.addSeries(series); 160 161 return dataset; 162 163 } 164 165 176 181 public static void main(String [] args) { 182 InternalFrameDemo demo = new InternalFrameDemo("Internal Frame Demo"); 183 demo.pack(); 184 RefineryUtilities.centerFrameOnScreen(demo); 185 demo.setVisible(true); 186 187 } 188 189 } 190 | Popular Tags |