LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-29-2004, 09:03 PM   #1
ludeKing
Member
 
Registered: Jul 2003
Location: NSW. Australia
Distribution: Ubuntu, Fedora, Slackware
Posts: 181

Rep: Reputation: 30
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!
 
Old 05-29-2004, 10:22 PM   #2
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

Rep: Reputation: 31
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;
      }

   }

}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
java newbie question method headers and if statements dflan98783 Programming 6 02-21-2007 11:18 PM
Method readLine() in Java...help KissDaFeetOfSean Programming 1 09-09-2005 12:41 AM
[java] Method signature precision pycoucou Programming 6 06-20-2004 11:31 AM
Java help (accessing array elemonts from another class or method) Tru_Messiah Programming 6 05-14-2004 09:20 AM
How to pass a file name into the main Method (C/C++) shassouneh Programming 2 06-20-2002 08:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration