access to another object

J

Joseph Wu

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
 
J

Joseph Wu

should i init another object to "calculator" class? but is that refer to
the same attribute ?
 
R

Roedy Green

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top