java bods - giving all classes access to swing components

Discussion in 'Technology' started by jamesrw, Aug 29, 2005.

Users Viewing Thread (Users: 0, Guests: 0)

  1. jamesrw

    jamesrw Member

    Joined:
    Aug 22, 2005
    Messages:
    31
    Likes Received:
    0
    java bods - giving all classes access to swing components

    This is a long shot - A question that has been bugging me for ages.

    How can you give all (or most) of the classes in a java access to swing components in a particular class.

    So say I have gui.java with all the swing code in it, and I want other classes to be able to output to a textarea, or disable menu items, in that class - how would I go about that?

    without passing all the components round in the constructors?

    hope this makes sense - anyone who can help gets a free gold star.
  2. 1615634792921.png
  3. Mr. Revel

    Mr. Revel Registered User

    Joined:
    Nov 12, 2001
    Messages:
    9,894
    Likes Received:
    0
    use the magic of inheritance...
  4. jamesrw

    jamesrw Member

    Joined:
    Aug 22, 2005
    Messages:
    31
    Likes Received:
    0
    so if I have

    class1 {
    int foo;
    }

    class2 extends class1 {
    // foo is inherited
    }

    class3 extends class2 {

    }

    ^^^ am I right in thinking foo will also be available in class 3?
  5. jamesrw

    jamesrw Member

    Joined:
    Aug 22, 2005
    Messages:
    31
    Likes Received:
    0
    my only problem with that is i dont want to have to inherit the first class 4 classes down the line if you like just to access one swing component : /

    i can just see it getting messy.

    will using an interface work?
  6. BRID

    BRID Has name in red. Staff

    Joined:
    Jan 31, 2003
    Messages:
    8,341
    Likes Received:
    218
    Location:
    Ever changing
    i dont code in java but what ive learned from OO in vb.net is that all your members/fields etc etc are always inherited and accessible no matter how much you inherit unless you specifically declare them as overrideable, overrides or whatever.

    that probably doesnt help.
  7. Phil Mitchell

    Phil Mitchell check me a dollar brer?

    Joined:
    May 19, 2005
    Messages:
    8,965
    Likes Received:
    1
    Location:
    Melbourne
    god i hope i dont have to do any java in 2nd year :lol:
  8. Jambon

    Jambon Jambons Disco Club

    Joined:
    Jan 1, 2001
    Messages:
    3,100
    Likes Received:
    0
    Location:
    Bumming Leon
    how wrong you are quick!!

    welcome to JAVA 2. :lol: :( :lol:
  9. Mr. Revel

    Mr. Revel Registered User

    Joined:
    Nov 12, 2001
    Messages:
    9,894
    Likes Received:
    0
    i fukkin hated second year Java. and Final year Java. Although i got away with not doing very much.
  10. Phil Mitchell

    Phil Mitchell check me a dollar brer?

    Joined:
    May 19, 2005
    Messages:
    8,965
    Likes Received:
    1
    Location:
    Melbourne
    nooooooooooooooooooooooooooooooooooo

Share This Page