implements x + implements y?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: implements x + implements y?

  1. #1
    Join Date
    Jan 2005
    Posts
    61

    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?

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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

  3. #3
    Join Date
    Jan 2005
    Posts
    61
    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

  4. #4
    Join Date
    Jan 2005
    Location
    Reisterstowwn, MD
    Posts
    72

    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.

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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

  6. #6
    Join Date
    Jan 2005
    Location
    Reisterstowwn, MD
    Posts
    72
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center