LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   how do you reload the 'main' method in Java? (http://www.linuxquestions.org/questions/programming-9/how-do-you-reload-the-main-method-in-java-187494/)

ludeKing 05-29-2004 09:03 PM

how do you reload the 'main' method in Java?
 
Hi all,
I have a java program that is basically a menu. the user chooses an option, which takes them to another class that does various things. The when that class is finished its stuff, I want it to return to the original class with the'main' method in it and reload it, so that the user can choose another option, or choose the option to quit.

At the moment, once the second class is finished it just quits, but Ineed it to return to the original class and restart again.

ie

Code:

public class original {

method here that displays a menu

another method that gets the value they enter

another method that calls the appropriate class depending on what they have entered.

public static void main(String args[]) {

call the three methods above, in order.
}

}

public class number1{

do some stuff

when done, return to original class, and reload 'main' // HOW?!?
}

please help!

eric.r.turner 05-29-2004 10:22 PM

Well, you don't "call" a class. You call methods of a class. Your main method could be something like this:

Code:

public static void main( String[] args ) {

  number1 n1 = new number1();
  boolean done = false;
  int choice = 0;

  while ( !done ) {

      displayMenu();
      choice = getMenuChoice();

      switch ( choice ) {
        case 0 :
            done = true;
            break;
        case 1 :
            n1.doSomething();
            break;
      }

  }

}



All times are GMT -5. The time now is 12:45 AM.