0

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?

Yossale
  • 14,165
  • 22
  • 82
  • 109

1 Answers1

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.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Thanks! How do you recommend accessing the MenuBar from within the internal frames? Should it be a Singleton? – Yossale Feb 27 '11 at 14:19
  • I don't think you should access the menu bar from the internal frames. In your main class, where the menu bar is created, you should define the InternalFrameListener as an instance variable. This class should also contain the method responsible for creating and adding new internal frames (called from the menu action opening the file). And this createFrame method should add the internal frame listener on the internal frame it creates. – JB Nizet Feb 27 '11 at 15:12