中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

一個簡單的繪制餅圖的 Java Bean 實例

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用
import java.awt.*;

/**
 * Simple charting bean. This version just draws a Pie Chart.
 *
 * It doesn't even label the pie slices; that is left as a
 * (non-trivial) exercise for the reader. Please read the
 * Technical Report "How Hard can it be to draw Pie Charts?" by Chris
 * van Wyck, Purdue/Bell Labs, 1989??, before you decide how easy
 * the work is going to be!
 */
public class ChartBean extends Component {

   /** The title to print on the chart */
   protected String title;

   /** the data to draw */
   protected ChartData data[];

   /** degrees in a circle */
   public static final int CIRCLE = 360;

   /** a set of colors to draw the pies in */
   protected Color[] colors = {
      Color.red,
      Color.blue,
      Color.green,
      Color.pink,
      Color.orange
   };

   /** Construct a ChartBean with a title */
   public ChartBean(String s) {
      title = s;
      setBackground(Color.white);
   }
   /** Construct a ChartBean with no title (no-arg constructor
    * required for Beans).
    */
   public ChartBean() {
       this(null);
   }

   public void setLabel(String s) {
      title = s;
   }

   public String getLabel() {
      return title;
   }
   public void setData(ChartData[] newStuff) {
      data = newStuff;
      repaint();
   }

   public void paint(Graphics g) {
      Dimension sz = getSize();
      int w = sz.width, h = sz.width;

      if (title != null)
         g.drawString(title, w/10, (int)(h*.9));

      if (data == null || data.length == 0) {
         g.drawOval(0, 0, w, h);
         g.drawString("Please provide some data!", w/10, h/2);
         return;
      }

      int total = 0;
      int angle = 0;
      int rad = 0;   // "radians" (actually degrees) to draw
      int colNum = 0;

      for (int i=0; i<data.length; i++)
         total += data[i].value;
      for (int i=0; i<data.length; i++) {
         rad = (int)(CIRCLE * ((float)data[i].value / (float)total));
         // System.out.println("data: "+data[i].name+";"+data[i].value+
         //   ",rad="+rad);
         g.setColor(colors[colNum++]);
         colNum%=colors.length;   // keep it in bounds
         g.fillArc(0, 0, w, h, angle, rad);
         angle += rad;
      }
   }

   public Dimension getMinimumSize() {
      return new Dimension(100, 120);
   }
   public Dimension getPreferredSize() {
      return new Dimension(200, 240);
   }
}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:使用 java.net.InterfaceAddress 獲取網(wǎng)卡信息

下一篇:使用ROW_NUMBER()的分頁存儲過程