Passing JMenuItem to Controller Class

后端 未结 1 1691
面向向阳花
面向向阳花 2021-01-25 10:14

I Have 3 sets of JMenuItem on a View class of the MVC framework. I want to refer to them in the controll class EventController. Can someone show me thi

1条回答
  •  天涯浪人
    2021-01-25 11:17

    Let your model export instances of Action that can be added to menus and buttons as needed. Because database access is inherently asynchronous, let each such action use a worker thread to query the database in the background while updating the table mode on the EDT. See also A Swing Architecture Overview concerning the relationship between Swing components and models.

    Addendum: Can you show me a code sample?

    • FileMenu is a very basic example of using Action to encapsulate functionality.

    • The example cited here uses Action more extensively in a JToolBar.

    • JHotDraw, cited here, is a very complex example that changes the available Action instances based on context, as discussed here.

    • This example offers a general examination of MVC in Swing.

    0 讨论(0)
提交回复
热议问题