Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > access to another object

Reply
Thread Tools

access to another object

 
 
Joseph Wu
Guest
Posts: n/a
 
      09-03-2003
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
 
Reply With Quote
 
 
 
 
Joseph Wu
Guest
Posts: n/a
 
      09-03-2003
should i init another object to "calculator" class? but is that refer to
the same attribute ?
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-03-2003
On Wed, 3 Sep 2003 19:27:44 +0000 (UTC), Joseph Wu
<(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection of object -> Array of another object?? qazmlp1209@rediffmail.com Java 7 03-13-2006 02:27 PM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Creating object of another object Maziar Aflatoun ASP .Net 1 04-06-2005 02:25 PM
How to access: a page from a User control, and another User controlfrom another one? qwerty ASP .Net 3 09-30-2004 05:32 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM



Advertisments