(SWING) Menu bar actions and state keeping

穿精又带淫゛_ 提交于 2019-12-11 18:04:47

问题


I'm writing a client app that's a bit similar to MS Excel - It has one menu bar , and you have several inner frames , each frame is a file in one of several states.

The basic flow is this : After opening a file , you can click on build , and after the build is completed you can export/save it (others scenarios are more complex).

What I'm interested in is how to change the state of the menu buttons every time you switch between frames: if you haven't pressed the "build" yet , the "export" should be disabled , but if you switch to a window where you've already pressed the "build" button and it's built , the "export" button should be enabled.

Is there a design pattern for handling something like this? Any Best Known Methods?


回答1:


Add an InternalFrameListener to every internal frame you create, and listen for internalFrameActivated events. The event contains the frame which has been activated. Ask this internal frame its state, to know if it has been built, and enable/disable the menu items accordingly.



来源:https://stackoverflow.com/questions/5133317/swing-menu-bar-actions-and-state-keeping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!