I am creating a project that with be using multiple jFrames. There is one important variable I have that every frame needs access to. Is there a way to use this variable through all of the frames?
Asked
Active
Viewed 2,337 times
1
-
An app. should generally have only a single `JFrame`. Consider using a `JDialog` or `JOptionPane` for the other free floating elements. – Andrew Thompson May 04 '11 at 15:18
-
Not true if he's using MDI or something analogous – gshauger May 04 '11 at 15:31
2 Answers
1
There are countless ways to solve this problem..
- Make it a static variable in some class that all of the JFrames can reference
- Make your own JFrame subclass and add a static field to it
- Make your own JFrame class and pass it into the constructor
And so on...

gshauger
- 747
- 4
- 16
0
If you have multiple JFrames you still have one main JFrame that will create other JFrames. So declare this variable in "main" JFrame and pass it through as constructor parameter of other JFrame

maks
- 5,911
- 17
- 79
- 123