(SWING)菜单栏动作和状态保持 [英] (SWING) Menu bar actions and state keeping

查看:163
本文介绍了(SWING)菜单栏动作和状态保持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个与MS Excel有点类似的客户端应用程序-它具有一个菜单栏,并且您具有多个内部框架,每个框架都是处于几种状态之一的文件.

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.

基本流程是:打开文件后,您可以单击build,在构建完成后,您可以导出/保存它(其他情况更复杂).

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).

我感兴趣的是每次在帧之间切换时如何更改菜单按钮的状态:如果尚未按下"build",则应禁用"export",但是如果切换到已经按下构建"按钮并已构建的窗口,即导出" 按钮应启用.

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?

推荐答案

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.

这篇关于(SWING)菜单栏动作和状态保持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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