Results 1 to 2 of 2
  1. #1
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default Classes and Objects Help

    I have two classes class A and class B. class A creates on object of class B by going: B b = new B(); Inside class B, there is an action listener that I want to run a method that is inside class A. I cant just create another object A from class b and run the method there, it has to be from from the class A that is the parent to class B. Any ideas? Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You can always pass a reference of A into the B object and use that reference. For e.g.,
    Java Code:
    public class A {
      B b;
      
      A() {
        b = new B(this);
      }
    }

    Java Code:
    public class B {
      A a;
      
      public B(A a) {
        this.a = a;
      }
    }

Similar Threads

  1. Constructors Objects and Classes
    By Tykk in forum New To Java
    Replies: 4
    Last Post: 10-10-2009, 11:31 PM
  2. classes as objects
    By kroiz in forum New To Java
    Replies: 4
    Last Post: 07-25-2009, 05:22 AM
  3. help with passing objects between classes
    By aruna1 in forum New To Java
    Replies: 7
    Last Post: 03-22-2009, 02:41 PM
  4. Replies: 1
    Last Post: 11-18-2008, 04:48 PM
  5. Objects and Classes
    By Aleve in forum New To Java
    Replies: 8
    Last Post: 12-31-2007, 08:05 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
  •