Java Swing GUI设计技术,用于用户操作验证(MVC-FSM) [英] Java Swing GUI design techniques for user actions validations (MVC-FSM)

查看:142
本文介绍了Java Swing GUI设计技术,用于用户操作验证(MVC-FSM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Swing实现了GUI,并且尽可能地遵循MVC模式。

我想知道如果MVC不是谜题的唯一部分。

是否在GUI设计中使用FSM?

我从未在GUI中使用FSM,我的方法是:在操作上,调用控制器的相应方法,以最终更新模型更新视图。

通常,在用户操作触发的请求中,我使用了一些简单的检查来确保用户应该能够执行该类型的操作:是启用了一个特定的组件?或者这种标签是否可见?等等

这似乎到目前为止工作,但是我不得不承认我是幸运的,而且不需要构建太复杂的复杂或精致的GUI。

我有之前(不同的应用程序 - 主要是在C ++中)构建FSM,并且我开始怀疑GUI中的FSM是否实际上被用作模式,我的方法即是对ActionListeners代码进行检查,用户看到什么以及启用了哪些组件或禁用等,以确定用户是否应该看到一些错误消息,而不是能够执行特定的操作,例如按钮承诺实际上是一个不错的主意,成熟的GUI应用程序。

所以,当开始设计一个GUI,除了如何实现MVC你适合/关联FSM在您的设计?

更新:

在评论中查看Dhruv Gairola文章后,我仍然对此感到困惑。

本文提到构建FSM虽然实际上绑定到计算器实现,这意味着即使计算器实现了在没有GUI的情况下实现用户输入,但通过命令行,仍然需要FSM。

我仍​​然不确定FSM是否在每个时间点验证用户的操作,是一种流行或有效的设计。

似乎可能是太多的努力,并且要求GUI已经完全设计,所有可能的用户操作都有已被映射到具体结果取决于具体的状态。

由于事实上没有任何评论只是一个答复,我倾向于t实际上没有使用FSM(用于验证用户对控件的操作)的帮助。



非常欢迎任何输入。

谢谢。

解决方案

可以这样说 - 设计模式主要阐述不同的设计原则,例如封装不同的内容,程序到界面,而不是实现等等,所以它不是你有使用模式或任何东西,基本上确保你的程序符合良好的设计原则。如果使用FSM作为特定设计,则使设计感觉到,建议您进行设计。通常鼓励模式,以便其他程序员能够根据他们对模式的了解,轻松了解您的逻辑并轻松扩展。没有任何严格的规则说你有使用MVC,你有使用blah blah blah ..结论:只要你应用的模式符合良好的设计原则,(即使你没有使用特定的模式),确保其设计良好,足够好让其他人轻松扩展和理解。这是我的两分钱。


I have implemented GUIs using Swing and always tried to follow the MVC pattern as much as I could.
I was wondering though, if MVC is not the only part of the puzzle.
Are FSMs used in GUI's design as well?
I have never used an FSM in a GUI and my approach was: on action, the corresponding method of the controller was called, to endup updating the model, finishing with updating the view.
Usually upon a request triggered by a user's action I used some simple checks to make sure that the user should be able to do the action of the kind:is a specific component enabled? or is the label visible of this kind? etc.
This seems to work so far, but I have to admit that I was "lucky" and did not have to build too complicated-sophisticated or elaborate GUIs.
I have build FSMs before (in different kind off applications -mainly in C++) and I started to wonder if FSMs in GUIs is actually used as a pattern and my approach i.e. to make checks on ActionListeners code, on what the user sees plus what components are enabled or disabled etc. to determine if the user should see some error message instead of being able to do the specific action that e.g. the button promises is actually a bad idea for full-fledged GUI apps.
So when starting to design a GUI besides how to implement the MVC do you fit/associate an FSM in your design?
UPDATE:
After reviewing Dhruv Gairola article in his comment, I am still puzzled on this.
The article mentions building an FSM which is though actually bind to the calculator implementation, meaning that even if the calculator was implemented getting user input without a GUI but via the command line, the FSM would still be needed.
I am still not sure if FSMs to validate user's action on each point in time, is a popular or valid design.
It seems that it could be too much effort and requires that the GUI has been designed completely in advance and all the possible user's action have been mapped to specific results depending on specific states.
Given the fact that there has no been any comments just a one reply, I am tending to think that may be FSM's (to validate a user's actions on controls) are actually not used.

Any input on this is highly welcome.
Thank you.

解决方案

lets put it this way- design patterns are mainly elaborations of the different design principles e.g. encapsulate what varies, program to an interface, not an implementation, etc. so its not that you HAVE to use a pattern or anything, basically make sure that the way you program conforms to good design principles. if using FSM for a particular design makes design sense, id advice you to go for it. usually patterns are encouraged so that other programmers are able to understand your logic and expand on it easily based on what they know about the pattern. theres no rigid rule saying that you HAVE to use MVC, you HAVE to use blah blah blah.. conclusion: as long as the pattern you're applying conforms to good design principles, (or even if you're not using a specific pattern), make sure its designed well and well enough for others to expand and understand it easily. thats my two cents worth..

这篇关于Java Swing GUI设计技术,用于用户操作验证(MVC-FSM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆