Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Problem with Methods

Thread view: 
Ed - 10 May 2006 19:22 GMT
I have a Class (class PublishStats) containing 2 methods. Method 1
(UpdateFields) formats text and inserts it into a DefaultStyledDocument
named, for example "wage1". Method 2 (PublishStats) uses a gridbagLayout to
display "wage1". This does not work opviously because wage1 being in method
1 is not availble to code in method 2.

Can someone suggest how I can overcome my problem? Is there a Global option
for a DefaultStyledDocument or something like that? Or is there a way to
call an object in method 1 from method 2? Help please! (There will be 25 of
these entries.)
Mark Thomas - 10 May 2006 19:52 GMT
> I have a Class (class PublishStats) containing 2 methods. Method 1
> (UpdateFields) formats text and inserts it into a DefaultStyledDocument
[quoted text clipped - 6 lines]
> call an object in method 1 from method 2? Help please! (There will be 25 of
> these entries.)

You need to appreciate the difference between local variables (those
declared inside a method) and instance variables (those declared outside
the method).  Any variable that needs to exist from one method call to
another should be an instance variable.  Note that this is in no way
'Global' - it is just the way objects encapsulate their state.

Mark
Oliver Wong - 10 May 2006 20:02 GMT
>I have a Class (class PublishStats) containing 2 methods. Method 1
>(UpdateFields) formats text and inserts it into a DefaultStyledDocument
[quoted text clipped - 6 lines]
> way to call an object in method 1 from method 2? Help please! (There will
> be 25 of these entries.)

   Perhaps you can make wage1 be a field of the PublishStats class so that
method 1 and method 2 can both access it. Hard to say if this will yield a
good OO design without seeing the rest of your code.

   - Oliver
Ed - 11 May 2006 14:26 GMT
Thnaks to both of you - very helpful

Ed

>I have a Class (class PublishStats) containing 2 methods. Method 1
>(UpdateFields) formats text and inserts it into a DefaultStyledDocument
[quoted text clipped - 6 lines]
> way to call an object in method 1 from method 2? Help please! (There will
> be 25 of these entries.)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.