如何使用 AspectJ 更改 JOptionPane 中的按钮
我需要更改应用程序中每个 JButton 的行为(这是一个研究项目)。我们认为使用一个方面来更改所有按钮的最佳方法是因为它可以保持干净——我们不必将所有 262 个实例更改为新类型。我们遇到了困难。我们编写的方面不会像对项目中的每个其他按钮那样修改 JOptionPane 中的按钮。这是我的建议:
after() returning(JButton button): call(*.new(..)) || call(* newInstance(..)) {
init(button);
}
这与 JButton 的所有其他构造函数匹配,但似乎缺少 JOptionPane 使用的构造函数。我如何访问他们的创作?我还是 AOP 的新手,所以也许这是不可能做到的。
I need to change the behavior of every JButton in an application (it's a research project). We felt that the best way to change all of the buttons using an aspect since it would keep it clean--we wouldn't have to change all 262 instances to a new type. We have run into a snag. The aspect that we have written does not modify the buttons in a JOptionPane like it does for every other button in our project. Here is the advice that I have:
after() returning(JButton button): call(*.new(..)) || call(* newInstance(..)) {
init(button);
}
This matches every other constructor of JButton, but it seems to be missing the one used by JOptionPane. How can I access their creation? I'm still new at AOP, so maybe this isn't even possible to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 AspectJ 默认忽略
javax
包。由于选项窗格按钮是在外观代码中创建的(例如,请参阅javax.swing.plaf.basic
包中的BasicOptionPaneUI.ButtonFactory
),这可能就是原因它被忽视了。也许看看更改配置选项以允许/包含 javax 包?I think AspectJ ignores the
javax
package by default. Since the option pane buttons are created in the look and feel code (seeBasicOptionPaneUI.ButtonFactory
in thejavax.swing.plaf.basic
package for example), that might be why it's being ignored. Maybe look at changing the configuration options to allow/include the javax package?