Results 1 to 18 of 18

Thread: static variable

  1. #1
    udhayageetha is offline Member
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    11
    Rep Power
    0

    Default static variable

    hi friends

    how to refresh the static variable...
    am creating static variable in class1
    using that variable in class2
    in class3 am calling class1
    in that time i need to refresh the static variable which i alredy created

    anybody help me

    with regards
    udhayageetha

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    What you mean refresh? When you load the same class in different classes, on each class have an independent static variables. So the original value stays as it is.

  3. #3
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Maybe "refresh" means to reset the value handled by that static variable.... I guess(base on OP's post)

    If that is, then use assignment operator on it....
    freedom exists in the world of ideas

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  5. #5
    udhayageetha is offline Member
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    11
    Rep Power
    0

    Default s its like reset

    i have created JPanel as static in classA & added that panel to container
    in classB am removing that panel
    finally am calling classA in button click..
    that time i cant get that panel..
    for that i want to reset the static variable..
    how to do that ??????

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  7. #7
    udhayageetha is offline Member
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    11
    Rep Power
    0

    Default class2 i given close option to close that panel (panel contents)

    i added so many components to that panel..
    i cant remove each & every.. so i removed that panel

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    This is not a variable define level issue. After removing the panel, on next call there is no such a panel(vanished with all components). So you have to define them all again.

    I'm wondering what's the requirement of removing the panel.

  9. #9
    udhayageetha is offline Member
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    11
    Rep Power
    0

    Default

    am calling again the classA in that time i want to reset the variables..
    actually i defined static variable in classA..

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Just think about that. When you call again what happened to the class A, basically to the content in your GUI.

    Can you show your code here.

  11. #11
    udhayageetha is offline Member
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    11
    Rep Power
    0

    Default

    cant sent code.. its so lengthy.. will explain the process.. give some idea..

    am having 3 modules.. created by 3 diff classes.. from login class am calling it by diff user name & pwd.. each module having logout button.. when am calling logout button i want to close that corresponding class & redirect to login page..

    again am enter into same module then that static panels r not visible...
    what i do

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    When did you initiated those components? If you use the same object reference it should work. But seems to me, you have deleted it and initiated again. At that time which constructor you are referring? Is that the one, you initiate the panel and all components?

  13. #13
    udhayageetha is offline Member
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    11
    Rep Power
    0

    Default

    am not using any constructor... is it needed?

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    With and without we can do it. But I want to know is that how did you initiate all components in your GUI? And also how did you define a object reference to your class from another class?

  15. #15
    udhayageetha is offline Member
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    11
    Rep Power
    0

    Default

    class A
    {
    static ELPanel panCode = new ELPanel();
    static ELPanel panCode = new ELPanel();
    static ELPanel panCode = new ELPanel();


    }

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  17. #17
    udhayageetha is offline Member
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    11
    Rep Power
    0

    Default

    actually its 3 different names... by mistake i sent it same name.. am using more then one panel in same class..when am clicking diff menu diff panels open.. when clicking close button am showing static page, and closig all panels.. for that am setting setvisible 'false'
    when am calling again that time also that setvisible property is false..

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I'm not clear what you are talking about. If I get correctly you have few number of GUIs. Call them in a menu.

    When you close button what you should do is, this is the normal procedure, dispose or exit a specific panel. But still you should have the reference to the panel. When you set visibility to true you can see it and, if you click false you can't see it.

    If that is what you didn't see in your application, I'm sure that you have something wrong with the instantiation of the panel.

Similar Threads

  1. About static variable
    By MarkWilson in forum New To Java
    Replies: 5
    Last Post: 06-27-2008, 02:43 PM
  2. Non-Static method in static context error
    By wizmang in forum New To Java
    Replies: 4
    Last Post: 04-24-2008, 09:51 AM
  3. Replies: 1
    Last Post: 08-07-2007, 06:05 AM
  4. Replies: 1
    Last Post: 08-01-2007, 10:25 PM
  5. Help with static variable counter
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-19-2007, 08:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •