-1

Alright the deal is I am trying to use the drawPie method to create my pie chart in an applet. After attempting google searches I find multiple tutorials that explain part of the process but not all of it. While trying to knit together partial information I am not getting the results I want.

    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;

    import javax.swing.JApplet;
    import javax.swing.JComponent;

public class JLW_PieApplet extends JApplet {

class PieData extends JComponent {
    PieValue[] slices = new PieValue[4];

    PieData() {
        slices[0] = new PieValue(35, Color.red);
        slices[1] = new PieValue(33, Color.green);
        slices[2] = new PieValue(20, Color.pink);
        slices[3] = new PieValue(12, Color.blue);

    }

    public void paint(Graphics g) {
        drawPie((Graphics2D)g, getBounds(), slices);
    }
}

}

4

2 回答 2

1

Ther isn't such method in Swing called drawPie. Without the contents of this method, we have no idea of how to help you

Try having a read through 2D Graphics and have a look at Ellipse2D in particular

The other problem I can see is you don't call super.paint(g) in your paint method. This is VERY, VERY, VERY important

于 2012-09-14T22:19:59.743 回答
0

You have a PieData component within your applet but you never add it, so you need to add it in init and bring in drawPie from your link above:

public class JLW_PieApplet extends JApplet {

   public void init() {
      add(new PieData());
   }

   class PieData extends JComponent {
      PieValue[] slices = new PieValue[4];

      PieData() {
         slices[0] = ...
      }

      @Override
      protected void paintComponent(Graphics g) {
         super.paintComponent(g);
         drawPie((Graphics2D) g, getBounds(), slices);
      }

      public void drawPie(Graphics2D g, Rectangle area, PieValue[] slices) {
      ...
于 2012-09-14T22:19:51.710 回答