简体   繁体   中英

Java: using methods of other classes

I am developing a project in java. I have a MainFrame, in this MainFrame I have some MyJPanel classes, and in Panels I have some MyJToggleButton classes.

Now, I am confused in some point. I would like to do this; When a MyJToggleButton is pressed,other MyJToggleButtons in other MyJPanels shell be selected.

Generally I have this kind of problems. In MyJPanel, I don't have the other panel's buttons nor methods.

I hope I could explain my problem, Thanks for your help

You describe something like this:

MainFrame
  |
  |_ MyJPanel.class
  |    |
  |    |_MyJToggleButton
  |
  |_otherMyPanel.class
       |
       |_otherMyJToggleButton

These are all View-Classes that represent some data to the user. If you want to add functionality you should write them in a controller. And your Business-Logic in a Model. You should read about MVC-Pattern

I suppose you represent the same thing with MyJToggleButtons.

What I may advice is to use MVC design pattern. You split your application to the Model part and View part. Controller part then listens to View and/or Model and every time change occurs in Model/View things are updated. Especially if you represent something in GUI in different places, both places would get a message from a Controller to be updated, because model changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM