• 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

Public Dataobject - how

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am going to have a main program and on this I will have a jtabbedpane, and each tabbedpanel will be a seperate java class, but I would like to be able to reference a public object and I want all to reference the same object. Each panel will have access to a data object and I only want one instance of the object that each panel is pointing too. How would I go about doing this?
thanks,
Dean
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not quite sure what you mean, Dean. Can you please give some "skeleton" code that demonstrates your ideas?
Thanks - Barry
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you're looking for the Singleton Pattern.
 
Dean Reedy
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am going to do is have a main Panel which is a sperate class
MainPanel.class
The MainPanel creates a TabbedPane with each Panel being a seperate class. I want to create an object in the MainPanel.class(data object) and be able to reference that same instance of the object in all of the panel classes.
Such as
Main.java - creates an object, loades it's data.
Now in the:
APanel, BPanel, CPanel, DPanel classes I want to reference the same instances of the object and any changes updates to the object are reflected in no matter which panel you are, thus if APAnel sets for example the color property to yellow than the CPanel sees that the color is yelllow. All classes referencing the same object.
I hope I explained it better. Basicly I am setting up a configuration file and want all java classes in a package to reference the same object and see the same information.
thanks,
Dean
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would look at the java.util.Observer interface and java.util.Observable class. Then you could possibly use all or part of the "Model-View-Controller" paradigm to relate all your classes to get your desired behaviour.
Sorry, I have no time right now to investigate further (got to go to work)
[ March 06, 2003: Message edited by: Barry Gaunt ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic