1

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?

willkara
  • 177
  • 3
  • 7
  • 16

2 Answers2

1

There are countless ways to solve this problem..

  1. Make it a static variable in some class that all of the JFrames can reference
  2. Make your own JFrame subclass and add a static field to it
  3. 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