-
implements x + implements y?
I'm not sure if this is part of my problem or not - I'm sure I have other errors but until I can get the compiler past this bit, I can't tell what they are.
Is it permissable to implement two or more classes in the main class definition? Following on from an earlier post, I'm trying to implement ActionListener and ItemListener (thanks for the earlier help Jsalle, but it was a bit complicated for me at this stage )
So my class definition looks like this:
public class fertConvert extends JFrame implements ActionListener implements ItemListener {
I've then added both action listener and ItemListener to the two lists that I want ItemListener running on, My idea is that ActionListener will direct the clicks to the relevant ItemListener.
So I've got 4 if / else statements in the actionListener bit - 2 that deal with clicks on the list (and should implement the itemlistener method) and two that handle separate button methods.
I might lose that in favour of a switch statement, but that's all a bit academic for now - the compiler keeps tripping at the first and last lines - the error messages are "{ expected" and "} expected".
I can't see why though, unless there's a problem with implementing two things like that?
-
You must write it like:
Code:
public class fertConvert extends JFrame implements ActionListener, ItemListener {
.
.
Too bad that my example was too complicated... after
all, extending off-the-shelf classes to suit ones needs
is one of the great things about object orented
programming...
eschew obfuscation
-
Thanks SJalle, I'll do that. Your example was only too complicated to me - I've only been at this a couple of weeks, so it's all a bit confusing, even though it's probabaly very simple.
Great fun though
-
Re: implements x + implements y?
Originally posted by will808
Is it permissable to implement two or more classes in the main class definition?
No, it is not, Java does not support multiple class inheritence like other languages such as C++. You may only extend one class. The question you are actually asking is "Can my class implement more then one interface?" The answer to this question is yes, you can implement as many interfaces as you whish.
-
you can implement as many interfaces as you whish
true, at least until you get the:
java.util.TooManyListenersException
I've never seen it though..
eschew obfuscation
-
Originally posted by sjalle
true, at least until you get the:
java.util.TooManyListenersException
I've never seen it though..
Learn something new everyday.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks