InternalFrame中的ActionListener,用于打开另一个InternalFrame

时间:2012-11-20 20:59:11

标签: java swing jmenuitem

我目前正在编写一个包含Swing的桌面应用程序,其中包含一个MainFrame,其中将运行多个InternalFrames。我想在每个单独的类中编写InternalFrames,以避免有一个巨大的MainFrame - 类。

现在我的问题是,我想在ActionListener的{​​{1}}中向MenuItem添加PopupMenu,在MenuInternalFrame中打开另一个InternalFrame {1}}。 MainFrame出现,但是当我点击MenuItem时没有任何反应。当我将代码放在MenuInternalFrame之外时,内部框架会出现。

问题必须与ActionListener有关。可能是我使用本地类和最终实例的解决方法来从ActionListener - 方法中访问InternalFrame吗?

以下是mouseClicked - 构造函数:

中代码的相关部分
MainFrame

任何想法可能是什么问题?提前谢谢。

1 个答案:

答案 0 :(得分:2)

请勿在{{1​​}}上使用MouseAdapter,使用JMenuItem并通过ActionListener添加:

JMenuItem#addActionListener(...)
相关问题