Results 1 to 6 of 6
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default Need fast reply: Getting all instances of class c in the running program?

    Hi!

    I would like to know if I can list all instances inside my java program given a certain class.
    So for example:
    If I have 2 jframes then I do something like:
    getInstances(JFrame.class);
    and it will return a list of both of those jframes.
    It should also be possible to do:
    getInstances(Graphics.class);
    and it would return the graphics areas of both jframes.

    Is this possible to achive in some way?
    Need fast answers as this job has to be done tomorrow.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default Re: Need fast reply: Getting all instances of class c in the running program?

    Word to the wise, don't bother mentioning your deadlines. It makes you seem impatient and rude.

    But why do you think you need to do this?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default Re: Need fast reply: Getting all instances of class c in the running program?

    Making a flexible reflecting window.
    If given an instance it will list all methods and fields, allowing you to execute them live.
    Some methods takes Classes instead of primitives thus I need a smart way to solve this.
    For example, the repaint method need a Graphics object. I would like to list all of them..

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default Re: Need fast reply: Getting all instances of class c in the running program?

    That's not really how painting works...
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default Re: Need fast reply: Getting all instances of class c in the running program?

    Dear kevin,
    I know how to paint an object in java. I should be obvious to see as I'm working with advanced features like Reflecting.
    The graphics was only an example.
    Some methods needs JFrames, some methods needs Point classes and so on. Listing all instances connected to a program is a good start.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,875
    Rep Power
    25

    Default Re: Need fast reply: Getting all instances of class c in the running program?

    list all instances inside my java program given a certain class
    If you scan the class file you can get a list of all the classes that are used in the class file.
    I don't know if you can have/use your own class loader for the java classes. If you can, then you could keep a list of the classes that have be read by the class loader.

Similar Threads

  1. Error initializing class instances
    By fr0s1yjack in forum New To Java
    Replies: 1
    Last Post: 06-22-2011, 04:58 PM
  2. Problem calling multiple instances of a class
    By virex in forum New To Java
    Replies: 1
    Last Post: 03-02-2010, 04:03 PM
  3. approx. 1000 instances of class?
    By artemff in forum CLDC and MIDP
    Replies: 0
    Last Post: 01-01-2010, 08:57 PM
  4. Class Instances stored in an ArrayList
    By Ersk in forum New To Java
    Replies: 4
    Last Post: 12-12-2009, 05:13 PM
  5. Problem with class instances
    By sdwinder in forum New To Java
    Replies: 7
    Last Post: 10-21-2009, 02:25 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
  •