> I hope to create a class that needs to extends both
> class Rectangle and JComponent, I know cannot
> extends TWO diff classes Rectangle JComponent at the
> same time, but how to do it?
Can't be done in Java. There is absolutely no way. If you need this, start learning C++
Agai, I construct another class as follows:
import javax.swing.*;
import javax.swing.JComponent;
public class JComponentRectangle extends Rectangle{
JComponent jc = null;
TransferHandler th = null;
Image image = null;
public JComponentRectangle(){
}
public TransferHandler setTransferHandler(TransferHandler newHandler){
jc.setTransferHandler(newHandler);
System.out.println("TransferHandler= "+ th);
return newHandler;
}
public Image setImage(Image image2){
image = image2;
System.out.println("image2 = "+ image);
return image;
}
}
but method public TransferHandler setTransferHandler seems not work at all,
what is wrong?
How can I define this setTransferHandler so that it really point to JComponent's setTransferHandler method?
Thanks
sunny
If i'm extending some class and use its method i would do this:
class A extends Point{
A(Point p){
super(p);
}
public double getX(){
int result=super.getX();
System.out.println(""+result);
return result;
}
}
hope you see the pattern there, of course this is only one of the way of doing it, but "super" keyword can be handy sometimes.
Edit: Sorry I misunderstood your ploblem completely. Yeah jc is never set to any value, that's why it's not working.
Message was edited by:
Icycool
Thanks, typing error for agai, should be again.
still very confused
for my code:
import javax.swing.*;
import javax.swing.JComponent;
public class JComponentRectangle extends Rectangle{
JComponent jc = null;
TransferHandler th = null;
Image image = null;
public JComponentRectangle(){
}
public TransferHandler setTransferHandler(TransferHandler newHandler){
jc.setTransferHandler(newHandler);
System.out.println("TransferHandler= "+ th);
return newHandler;
}
public Image setImage(Image image2){
image = image2;
System.out.println("image2 = "+ image);
return image;
}
}
I will create 2nd class BBB
public class BBB extends JComponentRectangle(){....}
then I will use third class CCC
public class CCC extends JComponent(){
TransferHandler newHandler = new TransferHandler();
BBB bb = new BBB();
bb.setTransferHandler(newHandler)
}
and I hope bb.setTransferHandler(newHandler) can be available,
you are right, when I run this code, it throws nullpointerException,
How to do it?
please help.
Thanks a lot!!
sunny