我想为我接管的程序的 Debug模式添加一个额外的功能。
我希望能够向 GUI 上的所有按钮、表格添加工具提示,以便它们在其中显示如下内容:
Class: JButton
Name: myShineyButton
Method: myShineyButtonActivateMethod
我知道使用反射的一般形式如下:
for(Fields bits: this.GetClass().getDeclaredFields){
if(bits instanceof Component){
String methodName = bits.getMethod().toString();
....
}
}
但是如何将工具提示添加到 GUI 上的每个项目呢?
最佳答案
您可能想查看 aspect-oriented programming (AOP)工具,例如AspectJ
。您可以检查/修改对象 after returning来自对其构造函数的调用。作为一个具体的例子,这个aspect ,引用here ,检测所有 EDT违反规则。更多示例可参见 here .
关于java - 显示带有使用反射关联的对象名称和方法的工具提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17742294/