Reputation: 89
I have started learning Java and I came across Adapter
class. I am trying to use one adapter class for two of my frame classes like below. Is it possible to generalise this adapter class, so many other classes can use this?
import java.awt.*;
import java.awt.event.WindowAdapter;
public class FrameAdopter extends WindowAdapter {
SampleFrame sf;
SampleFrame01 sf1;
FrameAdopter(SampleFrame sf) {
this.sf=sf;
}
}
Upvotes: 0
Views: 126
Reputation: 1765
Without knowing what you are trying to accomplish, you can generify like the following
public class MyClass<T extends Frame> extends WindowAdapter
{
T frame;
public MyClass(T frame)
{
this.frame = frame;
}
}
or in your case
public class FrameAdopter<T extends SampleFrame> extends WindowAdapter
{
T sf;
public FrameAdopter(T sf)
{
this.sf= sf;
}
}
Upvotes: 1