Slice.java.
- By Anand Jain
- July 17, 2000
Java To Go!
Your Way to a Flicker-Free 3D Pie Chart
Anand Jain
Listing 1. Slice.java.
import java.awt.*;
class Slice {
int value;
String legend;
static int x;
static int y;
static int height;
static int width;
int startAngle;
int arcAngle;
Color color ;
public Slice(int startAngle, int arcAngle, Color color) {
this.startAngle=startAngle;
this.arcAngle=arcAngle;
this.color = color;
}
public void draw(Graphics g) {
this.draw(g, this.color);
}
public void draw(Graphics g, Color color) {
g.setColor(color);
g.fillArc(x,y,height,width,startAngle,arcAngle);
}
public void drawXY (Graphics g, int x, int y, int height, int width, Color color) {
g.setColor(color);
g.fillArc(x,y,width,height,this.startAngle, this.arcAngle);
}
public void drawXY (Graphics g, int x, int y, int height, int width) {
g.setColor(color);
g.fillArc(x,y,width,height,this.startAngle, this.arcAngle);
}
public int getStartAngle() {
return startAngle;
}
public int getArcAngle() {
return arcAngle;
}
public static void setDimensions(int ax, int ay, int aheight, int awidth){
x = ax;
y = ay;
height = aheight;
width = awidth;
}
public void setColor(Color color) {
this.color = color;
}
public void drawRect(Rectangle ar, Graphics g) {
int x = ar.x;
int y = ar.y;
int height = ar.height;
int width = ar.width;
g.setColor(this.color.brighter());
g.fillRect(x,y,height,width);
g.setColor(Color.black);
g.drawRect(x,y,height,width);
}
}