This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, I have a question that I think has a very simple answer, forgive my ignorance if it is a dumb question. I am currently attempting my first set of Swing applications, I am moving to swing from a servlet background. I have written small swing applications before but I am about to start a larger scale project and I need to know if there is a swing/application way of doing something I found quite useful with servlet programming. I need to know how can a put something in "memory" and access it in any called class under it. i.e. is their a swing/application equivalent of a session I want for example to start my app, load a config file, and put the config setting somewhere that can be reached by anything else used in that application. This might be a stupid question or it might not be doable but I'm looking for a way to pass data between swing class without having to pass them on the constructor of each class. I hope this makes sense, Robert
There is nothing "SWING" about putting objects into memory. Use a Vector, use a HashTable or Hashmap, use whatever kind of object you want to store your information. You just have to make it public to whatever class you want to access it in. It is the same as any other JAVA Library.
I may not have asked the question properly or I may just not understand the anwser. I know I can store info in a Vector or a Hashtable, my question was ment to be more how do I access it. ie. App1 -(click)-> [Button1}
[Button1] -(triggers)-> new App2()
if in App1 I enter my name, how do I put in somewhere that I can go get it in App2 In a servlet I would just put it in the session and then get it again, my question is ment to be where/how do I put it somewhere so I can do a get of sort in App2 to get it. Robert
You either pass the data to app2 from app1 directly when you launch it, or through some kind of setData() method that you make up... The way I've usually done this is to fill up a HashMap with data gathered from all the fields of app1 in the action listener of the button in app1 and pass it to a setData(HashMap) method I made in app2 that fills out the fields of app2 with data from the HashMap. Note that both apps must agree on what keys you put data under in the HashMap.
If you need some global data that all apps may need to access, I would make a singleton class that holds a HashMap or Properties object and I set up constant String values for the keys to the data. Then any class that needs global data can just call this class...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.