1 22 23 24 import net.sourceforge.chart2d.*; 25 26 import java.awt.Dimension ; 27 import java.awt.Toolkit ; 28 import java.awt.event.WindowAdapter ; 29 import java.awt.event.WindowEvent ; 30 import javax.swing.JApplet ; 31 import javax.swing.JFrame ; 32 33 34 40 public class PieChart2DFrameDemo extends JApplet { 41 42 43 private JFrame frame = null; 44 private static boolean isApplet = true; 45 46 47 52 public static void main (String [] args) { 53 54 isApplet = false; 55 PieChart2DFrameDemo demo = new PieChart2DFrameDemo(); 56 demo.init(); 57 demo.start(); 58 } 59 60 61 64 public void init() { 65 66 68 Object2DProperties object2DProps = new Object2DProperties(); 70 object2DProps.setObjectTitleText ("LOC per Class"); 71 72 Chart2DProperties chart2DProps = new Chart2DProperties(); 74 chart2DProps.setChartDataLabelsPrecision (-3); 75 76 LegendProperties legendProps = new LegendProperties(); 78 String [] legendLabels = 79 {"PieChart2D", "LBChart2D", "LLChart2D", "GraphChart2D", "Chart2D", "Object2D"}; 80 legendProps.setLegendLabelsTexts (legendLabels); 81 82 int numSets = 6, numCats = 1, numItems = 1; 84 Dataset dataset = new Dataset (numSets, numCats, numItems); 85 dataset.set (0, 0, 0, .419f); 86 dataset.set (1, 0, 0, .284f); 87 dataset.set (2, 0, 0, .284f); 88 dataset.set (3, 0, 0, .714f); 89 dataset.set (4, 0, 0, .193f); 90 dataset.set (5, 0, 0, .241f); 91 92 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 94 95 PieChart2DProperties pieChart2DProps = new PieChart2DProperties(); 97 98 PieChart2D chart2D = new PieChart2D(); 100 chart2D.setObject2DProperties (object2DProps); 101 chart2D.setChart2DProperties (chart2DProps); 102 chart2D.setLegendProperties (legendProps); 103 chart2D.setDataset (dataset); 104 chart2D.setMultiColorsProperties (multiColorsProps); 105 chart2D.setPieChart2DProperties (pieChart2DProps); 106 107 if (!chart2D.validate (false)) chart2D.validate (true); 109 110 112 frame = new JFrame (); 114 frame.getContentPane().add (chart2D); frame.setTitle ("LLChart2DFrameDemo"); 116 frame.addWindowListener ( 117 new WindowAdapter () { 118 public void windowClosing (WindowEvent e) { 119 destroy(); 120 } } ); 121 122 frame.pack(); 123 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 124 frame.setLocation ( 125 (screenSize.width - frame.getSize().width) / 2, 126 (screenSize.height - frame.getSize().height) / 2); 127 128 if (!isApplet) start(); 129 } 130 131 132 135 public void start() { 136 frame.show(); 137 } 138 139 140 143 public void destroy() { 144 145 if (frame != null) frame.dispose(); 146 if (!isApplet) System.exit (0); 147 } 148 } | Popular Tags |