开发者

Use variable through multiple frames in java

开发者 https://www.devze.com 2023-03-03 11:21 出处:网络
I am creating a project that with be开发者_StackOverflow社区 using multiple jFrames. There is one important variable I have that every frame needs access to. Is there a way to use this variable throug

I am creating a project that with be开发者_StackOverflow社区 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?


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...


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号