Hi,

I am making a task-manager like program and i wanted to create a pie chart referring to the free/max memory (like the pie chart u see if you right click "My Computer.")

Can anybody please tell me how to do this (oh yeah, it's an application, not an applet)

THANK YOU SO MUCH IN ADVANCED,
C++

For pie charts, you would use the drawArc() method. I have an example, but I accidently deleted one of the source files, but I still have all of the class files. So, I can post the source files that I do have, if you want. I could also give you the class files so you can run it.

Hello C++,

Hi,

I am making a task-manager like program and i wanted to create a pie chart referring to the free/max memory (like the pie chart u see if you right click "My Computer.")

Can anybody please tell me how to do this (oh yeah, it's an application, not an applet)

THANK YOU SO MUCH IN ADVANCED,
C++

Do you mean you want to know how to draw graphics or how to monitor free/max memory?


regards,
George

server_crash, i would really appreciate it if you could post the code.

george, i already know how to monitor memory - i just want to create the pie chart(with colors)

server_crash, i would really appreciate it if you could post the code.

george, i already know how to monitor memory - i just want to create the pie chart(with colors)

I think I'll post them in attachments, and since one of the classes I accidently deleted, I will post the class files so you can run the program...But that is only if you ask me for the class files.

I'm sorry, but the actuall file that does the drawing of the arcs is the one delted, but I'll still post what I haven't got rid of. Maybe later, I will rewrite that file, so you can see. I do have the class file though, so you could actually decompile it if you knew how.

Attachments
import java.awt.*;
import javax.swing.*;

public class PieApplet extends JApplet {
	Color uneasyBeingGreen = new Color(0xCC, 0xCC, 0x99);
	Color zuzusPetals = new Color(0xCC, 0x66, 0xFF);
	Color zootSuit = new Color(0x66, 0x66, 0x99);
	Color sweetHomeAvocado = new Color(0x66, 0x99, 0x66);
	Color shrinkingViolet = new Color(0x66, 0x66, 0x99);
	Color miamiNice = new Color(0x33, 0xFF, 0xFF);
	Color inBetweenGreen = new Color(0x00, 0x99, 0x66);
	Color norwegianBlue = new Color(0x33, 0xCC, 0xCC);
	Color purpleRain = new Color(0x66, 0x33, 0x99);
	Color freckle = new Color(0x99, 0x66, 0x33);
	
    public void init() {
	Container pane = getContentPane();
	PiePanel pie = new PiePanel(10);
	pie.addSlice(uneasyBeingGreen, 1284);
	pie.addSlice(zuzusPetals, 1046);
	pie.addSlice(zootSuit, 281);
	pie.addSlice(sweetHomeAvocado, 232);
	pie.addSlice(shrinkingViolet, 176);
	pie.addSlice(miamiNice, 148);
	pie.addSlice(inBetweenGreen, 143);
	pie.addSlice(norwegianBlue, 133);
	pie.addSlice(purpleRain, 130);
	pie.addSlice(freckle, 127);
	pane.add(pie);
	setContentPane(pane);
    }
}
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class PiePanel extends JPanel {
  private PieSlice[] slice;
  private int current = 0;
  private float totalSize = 0;
  private Color background;

  public PiePanel(int sliceCount) {
	slice = new PieSlice[sliceCount];
	background = getBackground();
  }

  public void addSlice(Color sColor, float sSize) {
	if (current <= slice.length) {
		slice[current] = new PieSlice(sColor, sSize);
		totalSize += sSize;
		current++;
        }
  }

  public void paintComponent(Graphics comp) {
	super.paintComponent(comp);
	Graphics2D comp2D = (Graphics2D) comp;
	int width = getSize().width - 10;
	int height = getSize().height - 15;
	int xInset = 5;
	int yInset = 5;
	if (width < 5)
		xInset = width;
	if (height < 5)
		yInset = height;
	comp2D.setColor(background);
	comp2D.fillRect(0,0,getSize().width, getSize().height);
	comp2D.setColor(Color.lightGray);
	Ellipse2D.Float pie = new Ellipse2D.Float(xInset, yInset, width, height);
	comp2D.fill(pie);
	float start = 0;
	for (int i =0; i < slice.length; i++) {
		float extent = slice[i].size * 360F / totalSize;
	comp2D.setColor(slice[i].color);	
	Arc2D.Float drawSlice = new Arc2D.Float(xInset, yInset, width, height, start, extent, Arc2D.Float.PIE);
	start += extent;
	comp2D.fill(drawSlice);
      }
  }
}

class PieSlice {
  Color color = Color.lightGray;
  float size = 0;
  

  PieSlice(Color pColor, float pSize) {
	color = pColor;
	size = pSize;
  }
}

that didnt really help (no offense).

More help would be appreciated...

that didnt really help (no offense).

More help would be appreciated...

I know, I told you the file that would help was accidently deleted.

This article has been dead for over six months. Start a new discussion instead.