Problem with Methods

E

Ed

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.)
 
M

Mark Thomas

Ed said:
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.)
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
 
O

Oliver Wong

Ed said:
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.)

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
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top