Results 1 to 4 of 4

Thread: Invoke methods

  1. #1
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Invoke methods

    Hi,
    Im making a simple menu style interface. Ive got a class RegistryInterface which creates the interface menu and then a class RegistryApp with a main method to initiate it.
    My problem is i have the main menu public void doMenu, within this i have options where a user enters a number 1-4 and are then taken to the chosen menu option they decide.
    Below is the basic layout of it, if a user enters 1 then i want to invoke the method doAddStudent. I know how to store the value entered by the user etc i just need to know how i would invoke the doAddStudent method from inside the doMenu method.
    Thanks for the help.
    Java Code:
    public class RegistryInterface 
    {
        private Registry aRegistry = null;
        
        public RegistryInterface(Registry aRegistry)
        {
    
        }
    
        public void doMenu(Registry theRegistry)
        {
            System.out.println("Registry Main Menu");
            System.out.println("******************");
            System.out.println("1. Add a Student");
            System.out.println("2. Delete a Student");
            System.out.println("3. Print Registry");
            System.out.println("4. Quit");
            System.out.print("\nSelect option [1, 2, 3, 4] :> ");
    
            
        }
        
        private void doAddStudent()
        {
            
        }
        
        private void doDeleteStudent()
        {
    
        }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Invoke methods

    Look at your code. The System class has a member out which is an instance of PrintStream. PrintStream has a method println which you invoke in your code.

    Now, how do you think you would invoke doAddStudent which is a method of RegistryInterface?

    If that's not enough for you, go through the Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: Invoke methods

    You would simply call
    Java Code:
    doAddStudent();
    Depending on your style preferences, you could use the following
    Java Code:
    this.doAddStudent();
    "this" is a keyword that refers to the current instance.

  4. #4
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: Invoke methods

    thanks jlczuk, i didnt think it was that simple. Should have probably tried that first.
    Also thanks DarrylBurke, always handy to have a look over the basics again.

Similar Threads

  1. how to invoke sqlplus from jsp
    By shruthi.kashiprasad in forum New To Java
    Replies: 1
    Last Post: 04-12-2012, 10:05 AM
  2. invoke object in another class
    By storm88 in forum New To Java
    Replies: 1
    Last Post: 10-05-2011, 11:03 PM
  3. why should we invoke empty construtor
    By prabhajan in forum New To Java
    Replies: 5
    Last Post: 01-31-2011, 05:50 AM
  4. Invoke Applet
    By chankokchern in forum Java Applets
    Replies: 1
    Last Post: 07-29-2008, 04:35 PM
  5. Re address to jsp to that I invoke it
    By Marcus in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-09-2007, 04:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •