We are now ready for our menu to offer all three of
the possible options.
Code Adjustments
MenuItem lineChoice =
addMenuItem("Graph", "Line");
MenuItem barChoice = addMenuItem ("Graph", "Bar");
MenuItem pieChoice = addMenuItem ("Graph", "Pie");

public void
menuItemSelected (MenuItem item)
{
if (item == lineChoice)
graphChoice = 'L';
else if (item == barChoice)
graphChoice = 'B';
else if (item == pieChoice)
graphChoice = 'P';
repaint();
}

public void paint (Graphics g)
{
getInputData();
switch (graphChoice)
{
case 'L': {
drawLineGraph(g);
break;
}
case 'B': {
drawBarGraph(g);
break;
}
case 'P': {
drawPieGraph(g);
break;
}
}
} |