Problem with Methods

Discussion in 'Java' started by Ed, May 10, 2006.

  1. Ed

    Ed Guest

    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.)
     
    Ed, May 10, 2006
    #1
    1. Advertising

  2. Ed

    Mark Thomas Guest

    Ed wrote:
    > 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
     
    Mark Thomas, May 10, 2006
    #2
    1. Advertising

  3. Ed

    Oliver Wong Guest

    "Ed" <> wrote in message
    news:0cq8g.11033$8q.3264@dukeread08...
    >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
     
    Oliver Wong, May 10, 2006
    #3
  4. Ed

    Ed Guest

    Thnaks to both of you - very helpful

    Ed

    "Ed" <> wrote in message
    news:0cq8g.11033$8q.3264@dukeread08...
    >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.)
    >
     
    Ed, May 11, 2006
    #4
    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. Neo
    Replies:
    1
    Views:
    549
    Scott Allen
    Jan 7, 2005
  2. Buster Copley
    Replies:
    5
    Views:
    581
    Gianni Mariani
    Jul 7, 2003
  3. Tron Thomas
    Replies:
    10
    Views:
    1,121
    Tom Widmer
    Nov 10, 2004
  4. Oliver Wong
    Replies:
    14
    Views:
    1,679
    Chris Uppal
    Jun 13, 2006
  5. Kenneth McDonald
    Replies:
    5
    Views:
    380
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page