-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);
    }
}

}

KaitoX
  • 5
  • 1
  • 1
  • 2

2 Answers2

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

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
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) {
      ...
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • That's a fair point, but given the fact that we're missing so much of the code, it could also be a layout issue, or a problem with the drawPie method it self, or the fact that he fails to call super.paint(g) :P – MadProgrammer Sep 14 '12 at 22:22
  • Given the code presented + the link, it will work by adding this method. :) – Reimeus Sep 14 '12 at 22:27
  • No doubt it will "work", but that doesn't change the fact that it is still fundamentally flawed (the question, not the answer) – MadProgrammer Sep 14 '12 at 22:48
  • 2
    Thank you Reimeus. The answers you provided both initially and in your revisions were helpful. I still end up doing some of the leg work my own which is part of the point but you at least pointed me in the right direction without complaining about it not being an ideal textbook question. – KaitoX Sep 14 '12 at 23:06