Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Call a method in all instances of an object

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Location
    New Zealand
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Call a method in all instances of an object

    I'm making buttons for my game, which i am rendering with LWJGL. however, on the main menu there is a whole lot of buttons, an i was wondering if there was a way to make all of those buttons have their "renderButton" method called by only using one call to a superclass.

    Thanks,
    MaximusPrime


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Call a method in all instances of an object

    Put references to the buttons in an array and loop through the contents calling the method.

  3. The Following User Says Thank You to Norm For This Useful Post:

    MaximusPrime (March 14th, 2012)

  4. #3
    Junior Member
    Join Date
    Mar 2012
    Location
    New Zealand
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Call a method in all instances of an object

    Damn, I hoped that wasn't going to be the answer.

    Thanks anyway!

Similar Threads

  1. How to call a value from a different method to main
    By CrimsonFlash in forum What's Wrong With My Code?
    Replies: 13
    Last Post: October 22nd, 2011, 06:29 PM
  2. How do I call a method from the main method?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 19th, 2011, 08:37 PM
  3. Call method(s) within the same class
    By mwr76 in forum Object Oriented Programming
    Replies: 8
    Last Post: September 26th, 2011, 12:58 AM
  4. call super method outside of 'this'
    By questionmark in forum Object Oriented Programming
    Replies: 1
    Last Post: January 29th, 2011, 11:29 AM
  5. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM

Tags for this Thread