i'm learning java at uni just now and usually i prepare my program before the practical.
normally, myself and TClite try to program at the same time, conversing on msn messenger until one of us finishes first (him without exception)
so this week, i think it only fair to cheat![]()
anyway, does anyone know how i would insert a loop into the following program so that the program would ask for another country until the user presses the "cancel" button?
a very big thanks in advance too![]()
/**
* CheeseSwitch
*
*
* Choose a country using ListBox and a Switch Statement
*
* @author
*/
import javabook.*;
public class CheeseSwitch
{
public static void main (String[] args)
{
MainWindow mainWindow = new MainWindow("Country Chooser");
MessageBox messageBox = new MessageBox( mainWindow );
ListBox countryList = new ListBox( mainWindow, "Select Country");
int choice;
mainWindow.setVisible(true);
countryList.addItem("Scotland");
countryList.addItem("England");
countryList.addItem("France");
countryList.addItem("Greece");
countryList.addItem("Netherlands");
choice = countryList.getSelectedIndex();
switch ( choice )
{
case ListBox.NO_SELECTION :
messageBox.show("No selection made");
break;
case ListBox.CANCEL:
messageBox.show("Cancelled !");
break;
case 0 :
messageBox.show("Scottish Cheese");
break;
case 1 :
messageBox.show("English Cheese");
break;
case 2 :
messageBox.show("French Cheese");
break;
case 3 :
messageBox.show("Greek Cheese");
break;
case 4 :
messageBox.show("Dutch Cheese");
}
}
}
p.s. sorry in advance for the indentation, for some reason the board software likes to mess it up![]()
Bookmarks