// Here you can do something with the variable 'choice' confident that it has
// been set to some meaningful value in the routine 'actionPerformed'...
// Also check for errors in the input. E.g. if the choice lies outside the
// acceptable range then tell the user using some appropriate message.
// Parameters for drawing pie chart
double startAngle = 0.0;
double arcAngle;
int x = 10; // top left hand screen position (for the pie chart)
int y = 100;
int width = 200; // The total size of the pie chart
int height = 200;
arcAngle = 360.0 / 13.0; //(360 degrees divided equally by the 13 available colours)
// Parameters for drawing rectangle
int rectangle_height = 15;
// Parameters for drawing table
String colourString = " ";
int string_height = 15;
for (int colour = 1; colour <= 13; colour++)
{
// Select the colour
switch (colour) {
case 1:
g.setColor(Color.black);
colourString = "Black = 1";
break;
case 2:
g.setColor(Color.blue);
colourString = "Blue = 2";
break;
case 3:
g.setColor(Color.cyan);
colourString = "cyan = 3";
break;
case 4:
g.setColor(Color.darkGray);
colourString = "dark grey = 4";
break;
case 5:
g.setColor(Color.gray);
colourString = "grey = 5";
break;
case 6:
g.setColor(Color.green);
colourString = "green = 6";
break;
case 7:
g.setColor(Color.lightGray);
colourString = "lightgrey = 7";
break;
case 8:
g.setColor(Color.magenta);
colourString = "magenta = 8";
break;
case 9:
g.setColor(Color.orange);
colourString = "orange = 9";
break;
case 10:
g.setColor(Color.pink);
colourString = "pink = 10";
break;
case 11:
g.setColor(Color.red);
colourString = "red = 11";
break;
case 12:
g.setColor(Color.white);
colourString = "White = 12";
break;
case 13:
g.setColor(Color.yellow);
colourString = "Yellow = 13";
break;
}// end of switch (colour)
switch(choice) {
case 1:
// Case 1 - draw a colour graph
g.fillArc( x, y, width, height, (int)startAngle, (int)arcAngle );
startAngle = startAngle + arcAngle;
break;
case 2:
g.fillRect( x, y, width, rectangle_height);
y = y + rectangle_height;
break;
case 3:
g.drawString(colourString, x, y);
y = y + string_height;
break;
default:
break;
}// End of 'switch'
} // end of 'for' loop
//g.drawString("Choice 3 = Leave the program",20,60);