After you have completed your processing simply call the super's method.
For example:
public boolean requestFocusInWindow(){
if (IS_JRE_1_3){
requestFocus();
return false;
} else {
return super.requestFocusInWindow();
}
}
|---------+------------------------------------->
| | Dan Patten |
| | <[EMAIL PROTECTED]|
| | om> |
| | |
| | 30/08/2002 06:50 PM |
| | Please respond to "JDJList" |
| | |
|---------+------------------------------------->
>---------------------------------------------------------------------------------------------------------------|
|
|
| To: "JDJList" <[EMAIL PROTECTED]>
|
| cc:
|
| Subject: [jdjlist] RE: How to invoke method of super class using reflectio
n |
>---------------------------------------------------------------------------------------------------------------|
As I suspected, the invoke below calls the sub-class method recursively.
Any
ideas on how I call the parent?
I also tried getMethods and printed out all of the methods. Curiously it
listed the sub-class requestFocusInWIndow twice.
-----Original Message-----
From: Dan Patten [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 30, 2002 11:25 AM
To: JDJList
Subject: [jdjlist] How to invoke method of super class using reflection
We are flipping back and forth between 1.3.1 and 1.4.1 right now. We wanted
to handle a change from requestFocus used in 1.3.1 and prior to
requestFocusInWindow. We have a number of our own classes that extend Swing
Components so we thought we could over-ride requestFocusInWIndow so that it
would work whether we compiled in 1.3.1 or 1.4.1.
We though we might do the following:
public boolean requestFocusInWindow(){
if (IS_JRE_1_3){
requestFocus();
return false;
}
try{
java.lang.reflect.Method requestFocusInWindow =
super.getClass().getMethod("requestFocusInWindow",null);
Object result = requestFocusInWindow.invoke((JButton)this,null); //
.invoke(super,null); doesn't compile
return ((Boolean)result).booleanValue();
}
catch(Exception e){
return false;
}
}
My question is will the invoke statement actually invoke the
JButton.requestFocusInWindow or will it recurse into this sub-class method?
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
This message is for the designated recipient only and may contain
privileged, proprietary, or otherwise private information. If you have
received it in error, please notify the sender immediately and delete the
original. Any other use of the email by you is prohibited.
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm