更多秋千设计&行动 [英] More swing design & actions
问题描述
GUI
是一些 JFrame
) alt text http://img341.imageshack.us/img341/255/skjermdump.png
现在,这对于单向操作(如OpenDialog)非常有用。但是对于 DialogA
和 B
中的按钮的操作将不得不访问所有组件(将会有许多)在其对话框和控制器
中。这是我所在的地方。
我可以看到的唯一理智的方法是把它放在 DialogA / B
em>但是然后,我需要通过不需要它的类来将控制器
传递给所有的意大利面。真的不想要这个。
以前有人遇到过这个问题。那么我应该在哪里把这个 Action
?或者我应该放弃整个设计?
编辑:从别处获得了很好的答案。解决方案
在MVC中,控制器和视图互相访问,控制器将屏幕从模型屏蔽。最好的做法是把你的ActionHandler作为匿名类,只需回调你的看法,反过来又调用控制器。
如果你真的希望你有一个具有通用消息的Controller超类发送消息并传入HashMap,这样可以很好地分离代码,但增加了复杂性并删除了类型检查。
Im pretty new to gui programming so i've been reading through every post on this site about swing and design. Whats been answered over and over again is that one should have a multiton class for the actions. Like this: (GUI
being some JFrame
)
alt text http://img341.imageshack.us/img341/255/skjermdump.png
Now, this works great for one-way actions, like OpenDialog. But the actions for buttons in DialogA
and B
will have to have access to all the components (there will be many) in its dialog, and the controller
. This is where im stuck.
The only sane way i can see is to put it in DialogA/B
but i would then need to pass the controller
all the way down, through classes that dont even need it, and it'll get all spaghetti. Really dont want that.
Someone must have encountered this problem before. So where should i put this Action
? Or should i just drop the whole design?
Edit: got a good answer from elsewhere. Resolved.
In MVC the controller and the view access each other, the controller shields the view from the model. The best thing to do is to put your ActionHandler as anonymous class and have it simply call back to your view that in turn calls the controller.
If you really want you could have a Controller superclass that has generic messages to send a message and pass in a HashMap, that gives you good separation of code but, adds complexity and removes type checking.
这篇关于更多秋千设计&行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!