access to another object

Discussion in 'Java' started by Joseph Wu, Sep 3, 2003.

  1. Joseph Wu

    Joseph Wu Guest

    i have 3 classes,one is call "button" , "calculator" and
    "calculatorwindow" ,in the main() function of "calculator" it init an
    object/instance "window" to "calculator" and what it actually does is to
    create an "calculatorwindow" object and then add lots of buttons

    the problem is:how can i modify the attributes of the object "window"
    within the definition code of class "button" ?

    all the functions and attributes in those classes are not static,but the
    functions are public and can be used to revise the private attributes
     
    Joseph Wu, Sep 3, 2003
    #1
    1. Advertising

  2. Joseph Wu

    Joseph Wu Guest

    should i init another object to "calculator" class? but is that refer to
    the same attribute ?
     
    Joseph Wu, Sep 3, 2003
    #2
    1. Advertising

  3. Joseph Wu

    Roedy Green Guest

    On Wed, 3 Sep 2003 19:27:44 +0000 (UTC), Joseph Wu
    <> wrote or quoted :

    >the problem is:how can i modify the attributes of the object "window"
    >within the definition code of class "button" ?


    First, always capitalise the first letter of a class name.

    Next, don't use names that are already taken. You just confuse others
    and yourself.

    So I will call your classes MainWindow and ButtonControls.

    MainWindow can have public static methods that methods in
    ButtonControls can call by saying something like

    MainWindow.changeColorRandomly();

    Alteratively, MainWindow or some other class might instantiate a
    MainWindow object with new e.g

    MainWindow theMainWindow = new MainWindow();

    Then you can call instance methods of MainWindow with things like
    theMainWindow.changeColorRandomly();

    These are very basic oo concepts. Normally your text book should
    explain these to you. If it doesn't, see if you can find a more basic
    text that does. There is lots to read online as well. See
    http://mindprod.com/jgloss/personalbookshelf.html

    See http://mindprod.com/jgloss/instance.html
    http://mindprod.com/jgloss/static.html




    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Sep 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SteveS
    Replies:
    5
    Views:
    466
    Hermit Dave
    Dec 31, 2003
  2. nail
    Replies:
    0
    Views:
    1,564
  3. qwerty
    Replies:
    3
    Views:
    9,301
    Scott Allen
    Sep 30, 2004
  4. Peter Olcott
    Replies:
    5
    Views:
    382
    Peter Olcott
    Dec 6, 2005
  5. xodepp shrestha
    Replies:
    5
    Views:
    278
    Roedy Green
    Mar 1, 2013
Loading...

Share This Page