473,473 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating an Interface that Extends Another Class

I'm creating a sequence of JPanels that will each, in turn, be added to
(then removed from) a window (kind of like a wizard). I want these panels
to not only extend the JPanel class, but to implement an interface. I have
the interface defined in a separate class, like this:
public interface IPanel {
boolean onNext();
String nextPanel();
boolean hasCancel();
}

This leads to several problems. If I create one of my panels with:

JPanel myPanel = new JPanel();

and in the class definition line, I have:

class MySpecialPanel extends JPanel implements IPanel {
yada, yada, yada
}

If another class references one of these methods specified by IPanel, I get
error messages stating that method is not in JPanel.

If I define a new class with:

IPanel myPanel = new IPanel();

then try to add the new panel to an existing JPanel, I get an error message
that I can't do that with an IPanel and need to use a JPanel.

So even though the class states it extends JPanel and implements IPanel,
when I compile, I can't call an IPanel method if I define it as a JPanel
and I can't use the class as a JPanel if I define it as an IPanel.

It seems to me the perfect fix would be to create the interface and say it
extends JPanel, like this:

public interface IPanel extends JPanel {
blah, blah, blah
}

but I get errors when I try that and try to compile it. Is there any way to
specify IPanel as an interface that extends JPanel, so I can add IPanels
when I'd normally add JPanels?

Or is there a better way to handle this?

Thanks!

Hal
Jul 17 '05 #1
3 23421

"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:eg4jb.560923$Oz4.520446@rwcrnsc54...
I'm creating a sequence of JPanels that will each, in turn, be added to
(then removed from) a window (kind of like a wizard). I want these panels
to not only extend the JPanel class, but to implement an interface. I have the interface defined in a separate class, like this:
public interface IPanel {
boolean onNext();
String nextPanel();
boolean hasCancel();
}

This leads to several problems. If I create one of my panels with:

JPanel myPanel = new JPanel();

and in the class definition line, I have:

class MySpecialPanel extends JPanel implements IPanel {
yada, yada, yada
}

If another class references one of these methods specified by IPanel, I get error messages stating that method is not in JPanel.

If I define a new class with:

IPanel myPanel = new IPanel();

then try to add the new panel to an existing JPanel, I get an error message that I can't do that with an IPanel and need to use a JPanel.

So even though the class states it extends JPanel and implements IPanel,
when I compile, I can't call an IPanel method if I define it as a JPanel
and I can't use the class as a JPanel if I define it as an IPanel.

It seems to me the perfect fix would be to create the interface and say it
extends JPanel, like this:

public interface IPanel extends JPanel {
blah, blah, blah
}

but I get errors when I try that and try to compile it. Is there any way to specify IPanel as an interface that extends JPanel, so I can add IPanels
when I'd normally add JPanels?

Or is there a better way to handle this?

Thanks!

Hal


Yes, simply use MySpecialPanel where you need both JPanel and IPanel
functionality.

Silvio Bierman
Jul 17 '05 #2
SPG
Hi,

Another solution is to use IPanel as an abstract class.

public abstract class IPanel extends JPanel{
//Don;t forget your constructors!
public IPanel(........){
super(.......);
}

public abstract boolean onNext();
public abstract String nextPanel();
public abstract boolean hasCancel();
}

Then you can simply create your panel as you like and have access to both
interfaces

HTH,

Steve

"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:eg4jb.560923$Oz4.520446@rwcrnsc54...
I'm creating a sequence of JPanels that will each, in turn, be added to
(then removed from) a window (kind of like a wizard). I want these panels
to not only extend the JPanel class, but to implement an interface. I have the interface defined in a separate class, like this:
public interface IPanel {
boolean onNext();
String nextPanel();
boolean hasCancel();
}

This leads to several problems. If I create one of my panels with:

JPanel myPanel = new JPanel();

and in the class definition line, I have:

class MySpecialPanel extends JPanel implements IPanel {
yada, yada, yada
}

If another class references one of these methods specified by IPanel, I get error messages stating that method is not in JPanel.

If I define a new class with:

IPanel myPanel = new IPanel();

then try to add the new panel to an existing JPanel, I get an error message that I can't do that with an IPanel and need to use a JPanel.

So even though the class states it extends JPanel and implements IPanel,
when I compile, I can't call an IPanel method if I define it as a JPanel
and I can't use the class as a JPanel if I define it as an IPanel.

It seems to me the perfect fix would be to create the interface and say it
extends JPanel, like this:

public interface IPanel extends JPanel {
blah, blah, blah
}

but I get errors when I try that and try to compile it. Is there any way to specify IPanel as an interface that extends JPanel, so I can add IPanels
when I'd normally add JPanels?

Or is there a better way to handle this?

Thanks!

Hal

Jul 17 '05 #3
Hal Vaughan <ha*@thresholddigital.com> wrote in message news:<eg4jb.560923$Oz4.520446@rwcrnsc54>...
I'm creating a sequence of JPanels that will each, in turn, be added to
(then removed from) a window (kind of like a wizard). I want these panels
to not only extend the JPanel class, but to implement an interface. I have
the interface defined in a separate class, like this:
public interface IPanel {
boolean onNext();
String nextPanel();
boolean hasCancel();
}

This leads to several problems. If I create one of my panels with:

JPanel myPanel = new JPanel();

and in the class definition line, I have:

class MySpecialPanel extends JPanel implements IPanel {
yada, yada, yada
}

If another class references one of these methods specified by IPanel, I get
error messages stating that method is not in JPanel.

If I define a new class with:

IPanel myPanel = new IPanel();

then try to add the new panel to an existing JPanel, I get an error message
that I can't do that with an IPanel and need to use a JPanel.

So even though the class states it extends JPanel and implements IPanel,
when I compile, I can't call an IPanel method if I define it as a JPanel
and I can't use the class as a JPanel if I define it as an IPanel.

It seems to me the perfect fix would be to create the interface and say it
extends JPanel, like this:

public interface IPanel extends JPanel {
blah, blah, blah
}

but I get errors when I try that and try to compile it. Is there any way to
specify IPanel as an interface that extends JPanel, so I can add IPanels
when I'd normally add JPanels?

Or is there a better way to handle this?

Thanks!

Hal

If you want to work with your class as MySpecialPanel, you have to instantiate:
MySpecialPanel aPanel = new MySpecialPanel();

If you want to handle this class as IPanel, you have to do:
IPanel aPanel = new MySpecialPanel();

But this line of code will never work:
IPanel myPanel = new IPanel();
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rennie deGraaf | last post by:
I want to create a long-running RMI server, which makes an object available to remote hosts, and does nothing else. However, the server consistently exists with no exception or error after >=60...
21
by: Jason Heyes | last post by:
I want to allow objects of my class to be read from an input stream. I am having trouble with the implementation. Here are the different approaches I have tried: // Version 1.0 - Default...
3
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached...
6
by: Donal McWeeney | last post by:
I was under the impression that in an interface declaration I could inherit another interface declaration and the result would be that the inheriting interface could include the methods and...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
1
by: Marcel Hug | last post by:
Hi NG ! I have already written a task about MVC and I tried to get the best informations together. I would like to implement the MVC pattern and it work on the way I did it. At first i know the...
2
by: Kevin Frey | last post by:
In a derived class I am trying to redefine the implementation of a interface method defined in a base class - the base class interface method was not declared virtual. I have yet to actually...
4
by: Zerofury | last post by:
Okay here's what i'm trying to do. I want to create an array and fill it with objects, so that when i create a method to alphabetize them, all of the pieces (the price, name, ect) don't get all out...
4
by: tudyfruity18 | last post by:
I'm suppose to write an applet that contains two buttons Investment calculator and Loan Calculator. When the Investment Calculator button is clicked, a frame appears in a new window for calculating...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.