Implements interface

Hello,
I use JDK 5.0 with netbeans 4.0 beta 2
I get an error when I implement an interface like in this following example:
public class MyClass extends javax.swing.JPanel implements java.awt.event.KeyListener {
public MyClass () {
The text message is:
MyClassMyClass is not abstract and does not override abstract method key released in java.awt.event.KeyListener
Thank you for your help
Claude

An interface defines a contract with implementors of the interface. An interface may only contain public constants and public, abstract methods. An abstract method is a method declaration with no implementation (code) contained within.
If you implement an interface in your class, you must exactly duplicate the interface's method signature, including name, any parameters and the return type. Now, you do not necessarily need to actually place any code in the method, but you do at least need to have the method present in your class.
As an example:
public interface Foo {
public void bar()
public class FooImpl implements Foo {
final public void bar() {
// optional code here
- Saish
"My karma ran over your dogma." - Anon

Similar Messages

  • Public class implements interface

    I am taking my first crack at interfaces: I have superclass A which is a parent of class B, which implements interface C. I need to use class B to make 3 variable instances within class A. I think I will use interface C to make calculations based on the 3 variables. Where do you recommend that I declare and set values for the 3 variables if I need to output the values at the top, in superclass A?
    I'm just a little unclear on pulling these objcts together... thanks in advance.

    I am taking my first crack at interfaces: I have
    superclass A which is a parent of class B, which
    implements interface C. I need to use class B to make
    3 variable instances within class A. I think I will
    use interface C to make calculations based on the 3
    variables. Where do you recommend that I declare and
    set values for the 3 variables if I need to output the
    values at the top, in superclass A?
    I'm just a little unclear on pulling these objcts
    together... thanks in advance. If your variables are going to be used by your superclass A then they had better be declared there. You can work with them whereever you want.
    I'm not sure what you are saying about "...use interface C to make calculations based on the 3 variables." You can't do calculations inside an interface. Furthermore, if B extends A and implements C then A and C are going to be completely separate entities. Any reference to C, even if it is actually an object of type B, will not be able to use anything in A--unless you cast it to B, in which case there is no use in making an interface at all.
    I probably just confused you, but oh well...
    Jeff

  • Implementing interface views

    I have to add a main view to the portfolio items and integrate  the view WI_DMS of the web dynpro component DMS_DPR to the same. When I try to do it, it says  'WI_DMS does not implement a valid interface". Is there any way to implement the valid interface dynamically? PLease help.

    >i have been using ( implementing ) interfaces in the components, for example i used iwd_value_help. however i still have no clarity how WD framework is able to communicate with the component implementing interface iwd_value_help.
    Web Dynpro can create a component usage based upon the interface type alone.  This is very similar to normal ABAP OO when you create/get an instance of a class but only know the interface.  Basically this is polymorphism at the component level.
    >the basic question here is, what is wd framework, is it class implementing interfaces generated when we create views and other stuff. and this class( WD fw ) is going to call these implemented methods of the interface??
    Simple answer: yes, exactly as you describe.  Everything relates back to generated and local classes.  The framework can interact with them becuase all the generated classes implement SAP provide framework interfaces.

  • Perspective for Java technologies : implementing interface on late.

    In Java, to implements the adapter pattern's; we have to create a new class that have a link with the adaptee class and implements the adapter interface.
    class MyAdapter implements IAdapter
          public MyAdapter( Adaptee a );
    }or, if we need protected methods :
    class MyAdapter extends implements IAdapter
         public MyAdapter( Adaptee a );
    }then, to call the method void foo( IAdapter i ); ;
    we have to do xxx.foo( new MyAdapter( adaptee ) );it could be simpler if java allowed to implement interfaces after defining the java class.
    public class Adaptee
    }and then, in another file, something like,
    implementation of  IAdapter for class Adaptee
    }would be equivalent to
    public class Adaptee implements IAdapter
    }The advantage of the first method is that you can adapt very easy external classes from external jar file.
    thank's for coments.

    An interface is a contract which tells the compiler
    that a class that implements it implements a set of
    method signature which perform certain actions.That's right, but my idea is not to change the interface, but to change the external class, making it implements the existing interface.
    If you overlay an interface on someone else's class,
    the signature match (if there is one) could happen by
    coincidence. There's no guarantee that a method with
    a signature that matches one in your interface
    actually has the same function.I didn't say that an external class should be viewed as an interface without a specific implementation of this interface for the external class. But, instead of making a new class extending the first and implementing the interface, just define a specific implementation of the interface for this class, as if it was make at class declaration.

  • Implementation interface

    Hi guys. I have a test on array and inheritance and polymorphism. I didn't quite understand what is the benefit of implementing interfaces.
    Something like this:
    public class static Child extends Parent implement A,B,C
    Where A,B,C are interfaces.
    I need to get this straigth before the final test tomorrow. Thanks a lot.

    By implementing an interface, a class declares what it does. This means that the compiler and other classes can determine whether that class is suitable for some operations.
    So given your example Child which implements interfaces A, B, and C, there could be another class with method:
    public boolean doSomething(A aclass) {
    }This method can be given an instance of your "Child" class, or a different class which also implements the A interface.
    Interfaces say what a class does, as opposed to how it does it.

  • No implementation interfaces created using jaxb 2.0 ?

    Hi,
    I've downloaded the jaxb 2.0 RI and am trying to follow the short tutorial at http://java.sun.com/developer/technicalArticles/WebServices/jaxb/index.html.
    On trying to bind the schema via xsj,sh, which also is meant to generate the implementation interfaces (in an impl directory), I see these aren't created - the other classes are generated OK. Where or how should they be created ?
    thanks

    I am on the same boat. Have you found the answer to this?
    Thanks,
    Juan

  • Implements interface method at the derived class

    Hi all.
    I have a class (Derived) that extends another class (Base).
    In the base class (Base) there is a method f() with its implementation.
    In the interface (C) there is also f() method exactlly like in the base class (Base).
    The derived class (Derived) is implements the interface (C).
    My question is:
    Do i have to implement the method f() in the derived class (Derived) ?

    My guess is that you probably have to, even if it's just to call the parent's method.
    This all sounds pretty sketchy. Why don't you just make the BASE class implement your interface?

  • Extend abstract class & implement interface, different return type methods

    abstract class X
    public abstract String method();
    interface Y
    public void method();
    class Z extends X implements Y
      // Compiler error, If I don't implement both methods
      // If I implement only one method, compiler error is thrown for not
      // implementing another method
      // If I implement both the methods,duplicate method error is thrown by 
      //compiler
    The same problem can occur if both methods throw different checked exceptions,or if access modifiers are different..etc
    I'm preparing for SCJP, So just had this weired thought. Please let me know
    if there is a way to solve this.

    Nothing you can do about it except for changing the design.
    Kaj

  • Implements Interface Problem

    I am new to Java, hence I would like to know the reason behind the error produced by the codes given below:
    --- Scenario 1 ---
    public class MTServer{
    //Main Method
    // Creates a socket, accepts the socket.
    ServProtocol sp = new ServProtocol(client);
    sp.start(); // <-- No Problem
    public class ServProtocol extends Thread{
    @Overrides
    public void run(){}
    --- Scenario 2 ---
    public class MTServer{
    //Main Method
    // Creates a socket, accepts the socket.
    ServProtocol sp = new ServProtocol(client);
    sp.start(); //<-- Error Given - Method is undefined for start().
    public class ServProtocol implements Runnable{
    @Overrides
    public void run(){}
    The difference in the 2 scenarios were, one extends Thread, while the other implements Runnable.
    However, I do not understand the error behind it.
    Does the error persist because .start() is inherited from Parent Class when extends thread. However when implements Runnable, it does not provide function on this method?
    I would like to know how can I re-write the code so that I can retain the flexibility of Interface by implementing Runnable, as well as not having the error shown in Scenario 2.

    Don't post roughly what your code looks like because as here you introduce errors.
    Assuming your new class implements Runnable then it doesn't have a start method. You should instead pass it to a thread and start that. i.e.
    MyThingImplementingRunnable thing = new MyThingImplementingRunnable();
    new Thread(thing).start();

  • Derived class also implements interface?

    Hi guys,
    If a base class A implements an interface (e.g. Comparable), does a derived class of A also implement this interface (or is of this type e.g Comparable, if this is a more correct way to say it)??
    If so, would it be wrong to write "public class B extends A implements Comparable", because class A already implements it?
    I am aware of that class B will inherit methods from class B and that way have "compareTo()" method. But can objects of class B be plugged in for method parameter of Comparable ( someMethod(Comparable obj) )?

    LencoTB wrote:
    Hi guys,
    If a base class A implements an interface (e.g. Comparable), does a derived class of A also implement this interface (or is of this type e.g Comparable, if this is a more correct way to say it)??Yes. The way you said it is fine, although another way to say it is "Comparable is a base interface(or class) of derived class B"
    >
    >
    If so, would it be wrong to write "public class B extends A implements Comparable", because class A already implements it?Not necessarily, but it is unnecessary. The only reason you would do this is to specifically document that the class is changing the implementation of compareTo.
    >
    I am aware of that class B will inherit methods from class B and that way have "compareTo()" method. But can objects of class B be plugged in for method parameter of Comparable ( someMethod(Comparable obj) )?use "implements Comparable<B>"

  • Design Question - Class Must Implement Interface

    I'm not sure how to describe this in summary, really. I'd say that I sort of want multiple inheritance, but I don't want to be shot. :-P So let me describe the situation:
    I have an interface, DataEditingComponent<T>. The idea is that anything implementing the interface is capable of allowing the user to edit an object of type T. For example, a DataEditingComponent<Integer> would allow the user to input an integer. A DataEditingComponent<Map<SomeObj,Integer>> might represent an object capable of editing a table describing the number of instances of SomeObj. You get the idea. DataEditingComponent<T> describes three methods: getEditingData():T, setEditingData(T):void, and getDefaultEditingData():T. I'm assuming you can guess what those do.
    Well, the practical application of this interface is in the use of a Swing application. It provides a very clean and standardized way of adjusting the contents of components which edit data. Obviously, a JTextField would work about as well as a DataEditingComponent<String>, but for more complicated components (DataEditingComponent<GameWorldMap>, for instance), the standardized interface is very helpful.
    Since in practice everything that ever implements DataEditingComponent<T> extends JComponent, it would be nice to declare this as a requirement somehow. However, given that JComponent is extended into a number of various subclasses, I can't just go making DataEditingComponent<T> an abstract subclass.
    So far, the only conclusion I've reached is that I can take each and every JComponent subclass and extend it into an abstract subclass which implements DataEditingComponent<T>... but that's very ugly and quickly leads to other problems. And presently, I'm left casting things from one to the other, with which I am also not happy.
    So... any way out of this? Have I done something wrong design-wise? Or am I just stuck in a language limitation?
    Thanks for reading!

    I'm not sure how to describe this in summary, really.
    I'd say that I sort of want multiple inheritance,
    but I don't want to be shot. :-P So let me
    describe the situation:
    I have an interface, DataEditingComponent<T>. The
    idea is that anything implementing the interface is
    capable of allowing the user to edit an object of
    type T. For example, a DataEditingComponent<Integer>
    would allow the user to input an integer. A
    DataEditingComponent<Map<SomeObj,Integer>> might
    represent an object capable of editing a table
    describing the number of instances of SomeObj. You
    get the idea. DataEditingComponent<T> describes
    three methods: getEditingData():T,
    setEditingData(T):void, and
    getDefaultEditingData():T. I'm assuming you can
    guess what those do.
    Well, the practical application of this interface is
    in the use of a Swing application. It provides a
    very clean and standardized way of adjusting the
    contents of components which edit data. Obviously, a
    JTextField would work about as well as a
    DataEditingComponent<String>, but for more
    complicated components
    (DataEditingComponent<GameWorldMap>, for instance),
    the standardized interface is very helpful.
    Since in practice everything that ever implements
    DataEditingComponent<T> extends JComponent, it would
    be nice to declare this as a requirement somehow.
    However, given that JComponent is extended into a
    number of various subclasses, I can't just go making
    DataEditingComponent<T> an abstract subclass.
    So far, the only conclusion I've reached is that I
    can take each and every JComponent subclass and
    extend it into an abstract subclass which implements
    DataEditingComponent<T>... but that's very ugly and
    quickly leads to other problems. And presently, I'm
    left casting things from one to the other, with which
    I am also not happy.
    So... any way out of this? Have I done something
    wrong design-wise? Or am I just stuck in a language
    limitation?Hmm. The component is part of the view. The data is part of the model. Putting them together seems to go against the whole Model-View-Controller concept. You may want to have a look at how Swing separates the editing from the rendering from the model for complicated widgets such as JTable. The editors hava methods such as getEditorComponent() which returns the Component used to edit the data. Everywhere you are currently adding DataEditingComponent instances to your GUI, you can instead call a getDataEditingComponent() method, which can require that the returned object is a JComponent.

  • Implement interface (with many variables)

    If i have an interface that has 100 "public static final" variables and I access them by just "implementing" the interface in many other classes (so the variables are accessible via the variable name without any prefix), am I doing something wrong? The other approach of just accessing them thru the <class_name>.<variable_name> is the other option. Any insight, or is this a trivial difference and isn't worth worrying about? Thanks.

    Any insight, or is this a trivial
    difference and isn't worth worrying about? Thanks.Your solution is not considered proper because the class that inherits the constants will also expose them. So what should have been a private business is now a public matter.

  • Internal class implementing interface extending abstract interface :P

    Confused ha? Yeah me too. RIght here it goes.
    Theres an abstract interface (abstractIFace) that has for example method1() method2() and method3(). There are two other interfaces iFace1 and iFace2 that extend abstractIFace. Still with me? :P iFace1 only uses method2() whereas iFace2 uses method1(), method2() and method3(). Internal classes implementing these are then used. The reason is so that when returning an object one method can be used that will return different types of objects. But this doesnt work. It says that all the classes in the abstractIFace must be used/implemented but I only want method2() in iFace1 and all in iFace2.
    Just say what the f*ck if this is too confusing cos i think it is and i did a crap job explaining!! :P

    public interface IFace {
        void method1();
        void method2();
        void method3();
    public class Test {
        private static class Class1 implements IFace {
            public void method1() {
                System.out.println("method1");
            public void method2() {
                System.out.println("method2");
            public void method3() {
                System.out.println("method3");
        private static class Class2 implements IFace {
            public void method1() {
                throw new UnsupportedOperationException();
            public void method2() {
                System.out.println("method2");
            public void method3() {
                throw new UnsupportedOperationException();
        public static IFace createObject(boolean flag) {
            return flag ? (IFace) new Class1() : new Class2();
    }

  • Implementing interface using Oracle Fusion

    Hey All, my company is responding to a tender but one of the things it specifies is that if any middleware is required it should be implemented using Oracle Fusion.
    Up until this point I'd never even heard of Oracle Fusion but am trying to get up to speed fast, I need to know just enough to know we can do it and how hard it would be.
    To my question then, I guess they want us to use Fusion to build the interface between their existing app and ours, but Fusion seems to be a big stack of products... Can anybody point me to the specific product we would be using to build something like that, and some good resources to get an understanding of it. Also what is the learning curve like with this product suite?
    Any help appreciated.
    Martyn

    Hi Martyn,
    Fusion Middleware is a big stack but for integrations you can use SOA suite (or AIA). This in turn is a collection of multiple components. See below for some guidance.
    http://docs.oracle.com/cd/E21764_01/integration.1111/e10223/index.htm
    http://www.oracle.com/us/technologies/soa/soa-suite/oracle-soa-suite-11g-198758.pdf
    Regards,
    Neeraj Sehgal

  • Implement interface with static variable

    Hello all
    I want to create a class that has a static variable. In this class I also want to create a static function to change this static value. So I donot have to create any object when change the static variable.
    My problem is that this class should implement an interface (using facade pattern). As it implements an interface, it cannot have any static function in it.
    How I can overcome this problem. please help
    Many thanks
    shuhu

    My problem is that this class should implement an interface (using facade pattern).
    As it implements an interface, it cannot have any static function in it.Any class (including one that implements an interface) can have static methods.
    Do you mean you want the static method to be part of the interface? In this case you have a problem. Perhaps you should use an abstract class instead of an interface (the class could possibly implement the interface). Or perhaps you should rethink the need to have a static method.

Maybe you are looking for

  • Look & Feel Change For A Single Component of A Gui

    Hi All, I am using the wonderful windows XP look and feel that stefan krause has put together. However, I want to change just the background of the menubars. When I do menuBar.setBackground(color) this doesn't override what is the default colour set

  • IOS can't connect to Lion Server's VPN or navigate to /mydevices

    I've configured my host name, some seperate services for my VPN and now I'd like to introduce my iPad 2 to the mix as well. However each time I go to navigate to - http://server.myserver.private/mydevices, safari says the server cannot be found. Onto

  • Boot Camp 5 Download Issue

    Boot Camp 5.05.033 is supposed to be a .zip file.  However, after the dl I don't see this but do see:  Two blue folders (Boot camp and $WinPeDriver$) and an .xtml "page."  The folders contain several files each, none of which are .zip.  Am I download

  • Address book in Adobe?

    Hi, I am using Adobe to send my PDF files and in the old system, it remembered previous email addresses so I didn't have to type them in every time - they would come up as I started to type. Is this facility not available now? This is adding precious

  • Sun idm adapter for Enterprise Service Bus (Using MQ)

    Hi Can you please let me know if any sun idm adapter support Enterprise Service Bus (Using MQ) ? Thanks