简体   繁体   English

Java:使用其他类的方法

[英]Java: using methods of other classes

I am developing a project in java. 我正在用Java开发一个项目。 I have a MainFrame, in this MainFrame I have some MyJPanel classes, and in Panels I have some MyJToggleButton classes. 我有一个MainFrame,在这个MainFrame中,我有一些MyJPanel类,在Panels中,我有一些MyJToggleButton类。

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. 当按下MyJToggleButton时,将选择其他MyJPanels外壳程序中的其他MyJToggleButtons。

Generally I have this kind of problems. 通常我有这种问题。 In MyJPanel, I don't have the other panel's buttons nor methods. 在MyJPanel中,我没有其他面板的按钮或方法。

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 您应该阅读有关MVC模式的信息

I suppose you represent the same thing with MyJToggleButtons. 我想您用MyJToggleButtons代表同一件事。

What I may advice is to use MVC design pattern. 我可能建议的是使用MVC设计模式。 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. 控制器部分随后侦听View和/或Model,并且每次在Model / View中发生更改时,都会对事物进行更新。 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. 特别是如果您在不同位置的GUI中表示某些内容,则两个地方都会收到来自Controller的消息以进行更新,因为模型已更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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