如何使用 AspectJ 更改 JOptionPane 中的按钮

发布于 2024-09-11 04:11:04 字数 376 浏览 0 评论 0原文

我需要更改应用程序中每个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-09-18 04:11:04

我认为 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 (see BasicOptionPaneUI.ButtonFactory in the javax.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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文