News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1194054284:v:use_geshi-1:v:type-java5

Started by Guest, Nov 03, 2007, 01:44 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Guest

/**
 * Menu Driven Array
 * @author jaybachatero
 *
 */
public class Menu
{
   // The length of the array.
   int menuLength = 10;
   // Start the menu string.
   String menu = "";
   // String menu[menuLength] = new Array();
   // Number of menu items.
   int totalMenuItems = 0;
   // Current step to fall back to.
   int currentStep = 1;
   // Did we exit already?
   boolean menuExit = false;

   /**
    * Adds items to the menu.
    * @param item
    */
   public void addMenuItem(String item)
   {
      // Can't add more if the menu already exited.
      if (this.menuExit == false)
      {
         // Increase it.
         this.totalMenuItems++;
         // Set the menu item.
         this.menu += "\n" + this.totalMenuItems + ". " + item;
      }
   }

   /**
    * Get method for the menu.
    * @return menu items.
    */
   public String getMenuItems()
   {
      return this.menu;
   }

   /**
    * This method adds the last item in the menu.  That is the exit item.
    * @param exit
    */
   public void addMenuExitItem(String exit)
   {
      if (this.menuExit == false)
      {
         if (exit == "")
            this.addMenuItem("Exit");
         else
            this.addMenuItem(exit);

         // Ok we exited and there is nothing you can do now.
         this.menuExit = true;
      }
   }

   /**
    * Returns the id of the exit step.
    * @return
    */
   public int getExitStep()
   {
      return this.totalMenuItems;
   }

   /**
    * Adds a header and a footer to the menu.
    * @param text - the string for the header/footer.
    * @param type - the type of string we are adding.  header, footer
    */
   public void addMenuHeaderFooter(String text, String type)
   {
      if (type == "header")
         this.menu = text + this.menu;
      else if (type == "footer")
         this.menu += "\n" + text;
   }

   /**
    * Increases the current step.
    */
   public void increaseCurrentStep()
   {
      this.currentStep++;
   }
}