• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to manage class relationship?

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I have several classes which extends JPanel each one. in the main frame i realize all the panel by composition.
when i run the main frame(the GUI) i want real relationship between the classes.
for example , one panel has a button and the other panel has a list , i want the button in the fist panel to add item in the second panel's list.
i tried this way:

in this way i dont add item to the list in the first panel like wanted. i cant use static cuz i need several instances of this object , if i use static it will shre all the data among the objects.
how can i make the button in the first panel to changhe the state of the list in the second panel without static references.
thanks

 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since your code is incomplete, I ask a stupid question:
Did you add a listener on the JButton bt?
In the actionPerformed method, it is better to to test "if (JButton)e.getSource()==bt".
W.
 
Wilfried LAURENT
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another question is :
How do you get a hand on the reference of FirstPanel which is declared in SecondPanel? You need to have this reference to add it to a frame or window. I mean : are you sure that the FirstPanel you are displaying on the screen is the same as the FirstPanel whose JList you are adding elements to?
W.
reply
    Bookmark Topic Watch Topic
  • New Topic