Listener Interface implementation questions

Dear all experts,
I am getting a bit confused of the "standard" way of implementing listener interfaces.
I found that there are 3 general methods:
1) create an extra class implementing the interface.
2) implement the interface as an inner class
3) using the existing class to implement the inferface :
eg:
public class oneofmyclass implement FocusListener
public oneofmyclass()
constructor....
all my other methods.........
the interface methods......
Why there are so many ways to do it?
what's the differences/benefits of each??
Thx

I am getting a bit confused of the "standard" way of implementing listener interfaces.
I found that there are 3 general methods:
1) create an extra class implementing the interface.
2) implement the interface as an inner class
3) using the existing class to implement the inferfaceThere isn't much difference between 1) and 2). The first alternative creates a named inner class
(that implements the listener interface) while the second creates an anonymous class using that
listener interface. Alternative 3) exposes the interface to the outer world, i.e. your class may be
attached to some listener list (in some observable) it really wasn't meant for.
I prefer 1) or 2) If the actual code for the listener is small I use 2), otherwise I use 1) but that's
just for readability reasons. I almost never use 3) because I don't want my class to be hooked
up to any observable it wasn't designed for.
kind regards,
Jos

Similar Messages

  • Servlet also implementing listener interface

    Hi,
    Can I have a servlet "extends HttpServlet" and "implements HttpSessionListener" at the same time? If I add both a listener and a servlet element in deployment descriptor, how the container will instaniate/initialize the servlet/listener?
    Thanks.

    Hi,
    Can I have a servlet "extends HttpServlet" and
    "implements HttpSessionListener" at the same time? Yes, of course. Plenty of examples of this elsewhere in Java (e.g., java.awt.Canvas).
    If
    I add both a listener and a servlet element in
    deployment descriptor, how the container will
    instaniate/initialize the servlet/listener?Same way it always does: by calling the HttpServlet ctor. The fact that there's a new Listener interface doesn't affect that.
    You're on the hook to implement the interface's methods and make sure they're called appropriately.
    Whether this is a good design or not is another question. (I don't know the answer.)
    Thanks.You're welcome. - %

  • In servlet what Event Listener interface defines session will passivate()

    Hi!
    In servlet what Event Listener interface defines session will passivate() method?
    Thanx

    Hi!
    for the above question which one will be the correct answer?
    1.HTTPSessionEventListener
    2.HTTPSessionListener
    3.HTTPSessionAttributeListener
    4.HTTPSessionActivationListener

  • Component interface ( implementation ) is missing

    Hello,
    I had imported from NWDI one SWC that have some DC's. When I create a project in NWDS form one DC  that have a dependence from another DC where the project has bveen already created in NWDS I have the following error message for this DC: "<error: missing compoent> component interface ( implementation ) is missisng". When I delete the referenced DCt from NWDS and sync used DC's from the DC with the error, the problem is solved.
    But, when I create the refereced DC again, the DC that use this, the error missing component occurs again.
    Anybody have any ideia about this?
    thanks in advance.

    You are absolute right in this, but this is not my problem. I will try to explain it once again. Currently I have the following configuration on my PE router
    router ospf 5628 vrf INET
    network 194.154.224.0 0.0.31.255 area 0
    the f0/0 interface has this configuration
    interface FastEthernet0/0
    ip vrf forwarding INET
    ip address 194.154.236.43 255.255.255.248
    The problem is, that using this configuration, hello packets are send also through other interfaces of my PE router, which are part of the same ip address range specified under ospf process and are in the same vrf. In other words, hello packets are send to my Internet customers, which is not good. Because it is not possible to configure passive interface under ospf in the VRF, I decided to make the network statement more specific. I have changed the configuration to
    router ospf 5628 vrf INET
    network 194.154.236.40 0.0.0.7 area 0
    and got the message
    %OSPF: OSPF not enabled on FastEthernet0/0
    The question is, why is OSPF not enabled on my f0/0, as the ip address of my f0/0 is part of a 194.154.236.40 0.0.0.7 network ?

  • Is the remote interface implemented by some class

    Hi,
    I have a simple question, googled, no help.
    I am trying to udnerstand, where exactly is the remote interface implemented ?
    I mean, i know that it contains all the business methods which have a body in the bean.
    But is the remote interface implemented somewhere ? Is there any class which implements the Remote interface ?
    thanks
    S

    Sarvananda wrote:
    Hi,
    I have a simple question, googled, no help.look better...
    I am trying to udnerstand, where exactly is the remote interface implemented ?
    I mean, i know that it contains all the business methods which have a body in the bean. so, that's what implements it :)
    But is the remote interface implemented somewhere ? Is there any class which implements the Remote interface ?
    the bean class :)
    But the actual implementor is a class generated by the appserver that delegates to the bean class.

  • HSRP Interface Tracking Question

    I have a pair of 7206 routers for Internet access.  The Internet was provided over OC3, and used interface POS1/0.  I just upgraded the Internet to Ethernet so now the interface is GigabitEthernet 0/3.
    I just discovered that there there is another interface that uses POS1/0 as an HSRP tracking interface.  So my question is:   Can I just remove the old tracking interface and add the new one? Or is there another prefered method to do this?
    My current HSRP interface:
    interface GigabitEthernet0/1.21
     description INET
     encapsulation dot1Q 21
     ip address x.x.x.x 255.255.255.240
     ip broadcast-address x.x.x.x
     no ip redirects
     ip accounting output-packets
     ip flow ingress
     ip nbar protocol-discovery
     no snmp trap link-status
     standby 1 ip x.x.x.x
     standby 1 priority 105
     standby 1 preempt
     standby 1 track POS1/0
    Thanks!
    Ray

    Ray
    While it is correct that you can just change the HRP interface to track the Ethernet interface be aware that it may not work quite the same way. With POS and most serial interface implementations if communications with the peer is lost then the loss of keepalives will change the interface state to line protocol down and that is what the interface tracking is looking for. However with an Ethernet interface if you lose communication with the peer the interface may still be in a line protocol up state. In that circumstance interface tracking will not detect the problem.
    HTH
    Rick

  • Iterator Interface.A question please.

    I am unable to grasp the meaning of the following below :
    As we all know,Interfaces have abstract methods,(ie methods that
    have no body) and any class that implements the Interface has to
    implement the methods defined in the interface.That is,write the body for those methods.
    So far so good.
    Now coming to Collections called Vector.
    We have the 'Iterator' interface implemented by the vector class.
    The Iterator interface has the methods hasNext(),next().
    and we have the following code in the our class which iterates thru'
    the vector:
    MyClass item;
    while(iter.hasNext())
    item = (MyClass)iter.next();
    // Do something here.....
    Now we are using the methods hasNext() and next() above.
    But as they belong to the Iterator interface,(which means they
    are basically methods with no implementations) then how is iteration
    possible? We havent defined anything in the hasNext() method or the next()
    so how does Java automatically start iteration
    Has any one understood my question?Arent hasNext() and next() supposed
    to be methods with no body???
    If I am saying iter.hasNext(),that means hasNext() has been defined
    somewhere to iterate thru the vector?
    I am just confused regarding this issue as to how is hasNext() and next()
    being implemented as I as the programmer have not implemented them
    in my code
    Please can some one answer my question?
    Regards
    Ajay

    Thanks Will.
    Regarding the question,then why define an Iterator interface when
    the collection class implements the functionality?
    Why not define the methods hasNext() and next() in the Object
    class?
    So by default,all classes extends the Object class ,we
    cud use the hasNext() and next() method?
    No??? Or am I wrong?

  • Iterator Interface.A question please......respond

    I am unable to grasp the meaning of the following below :
    As we all know,Interfaces have abstract methods,(ie methods that
    have no body) and any class that implements the Interface has to
    implement the methods defined in the interface.That is,write the body for those methods.
    So far so good.
    Now coming to Collections called Vector.
    We have the 'Iterator' interface implemented by the vector class.
    The Iterator interface has the methods hasNext(),next().
    and we have the following code in the our class which iterates thru'
    the vector:
    MyClass item;
    while(iter.hasNext())
    item = (MyClass)iter.next();
    // Do something here.....
    Now we are using the methods hasNext() and next() above.
    But as they belong to the Iterator interface,(which means they
    are basically methods with no implementations) then how is iteration
    possible? We havent defined anything in the hasNext() method or the next()
    so how does Java automatically start iteration
    Has any one understood my question?Arent hasNext() and next() supposed
    to be methods with no body???
    If I am saying iter.hasNext(),that means hasNext() has been defined
    somewhere to iterate thru the vector?
    I am just confused regarding this issue as to how is hasNext() and next()
    being implemented as I as the programmer have not implemented them
    in my code
    Please can some one answer my question?
    Regards
    Ajay

    Thanks for yr reply.
    So you mean to say the the Iterator methods hasNext()
    and next()
    are being implemented by the Vector class.right?Not exactly. The Vector class defines an inner class, and it is this class that implements the Iterator interface, and so these two methods. When you write code like
    Vector myVector = new Vector();
    // code to fill myVector...
    Iterator it = myVector.iterator();the call to the iterator() method tells myVector to give you an instance of this inner class. The Vector class itself doesn't implement next() or hasNext().
    Then why define an interface with these methods at
    all?
    Why not give concrete bodies to these methods and put
    them in
    the Object Class.If you did that, then all classes would inherit them - all classes would be iterators. That wouldn't make sense, though, as clearly not all classes are meant to be used to iterate over collections of objects.
    Iterator is an interface so that a consistent API can be defined for iteration. As iterators are used in lots of different places, it is very helpful to have all of them guaranteed to have next() and hasNext() methods (amongst others). It is also very helpful to be able to call the iterator() method on any Collection class and know that the object that is returned, regardless of its implementation, will be of type Iterator.
    Then we can call them polymorphically.???But that's what you're doing - Vector and ArrayList (for example) have different implementations of Iterator, but code that iterates over them doesn't need to know that. As both return objects that implement the Iterator interface, they are interchangeable; that's polymorphism at work.

  • Registering an action listener interface

    How do i register an action listener interface to a java program which has three textfields and three buttons. addition,multiplication and subtraction respectively so that when i click on a button it sums,multiply,and subtracts the numbers and displays the output in the third textfield box using the swing components.

    ** BUT a more important point i wanted to
    express/share is that... it is actually better if we
    TRY to avoid using ActionCommand while
    handling such scenarios !!!Let me show the way i modified the Calculate.java pgm..
    (Thanks to @Wildcard82 )
    //~~~~~~~~~~~~
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    public class Calculate extends JFrame implements ActionListener
        private static final long serialVersionUID = -1558653254398328438L;
        private JTextField field1, field2, field3;
        private JButton add, subtract, multiply;
        // HAVE to be instance fields now...
        // so that they're visible in the actionPerformed() method...! :)
        private enum Operations{
            add,subtract,multiply
        public Calculate()
            setLayout(new GridLayout(2,3));
            field1=new JTextField(5);
            field2=new JTextField(5);
            field3=new JTextField(5);
            add = new JButton("add");
            //add.setActionCommand("add"); // * NO need to set the Action-Command..!
            add.addActionListener(this);
            subtract = new JButton("subtract");
            subtract.addActionListener(this);
            multiply = new JButton("multiply");
            multiply.addActionListener(this);
            add(field1);add(field2);add(field3);
            add(add); add(subtract); add(multiply);
        } /* default c'tor */
         * @param args
        public static void main(String[] args)
            Calculate c = new Calculate();
            c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            c.setVisible(true);
            c.pack();
        } /* end main() */
         * A simpler & nicer version of actionPerformed() that works
         * even when you internationalize your Calculator App...
         * ..since, it does NOT depend on Action-Commands but just on the
         * Event-Source objects, which DON"T change when you do I18N...! :)
        public void actionPerformed(ActionEvent ae)
            Object source = ae.getSource();
            if(source==add)calculate(Operations.add);       
            else if(source==subtract)calculate(Operations.subtract);       
            else if(source==multiply)calculate(Operations.multiply);       
        } /* end method() */
        private void calculate(Operations operation)
            int n1, n2;
            n1=Integer.parseInt(field1.getText());
            n2=Integer.parseInt(field2.getText());
            if(operation==Operations.add)
                field3.setText(String.valueOf(n1+n2));
            else if(operation==Operations.subtract)
                field3.setText(String.valueOf(n1-n2));
            else if(operation==Operations.multiply)
                field3.setText(String.valueOf(n1*n2));
             else
                field3.setText("");
        } /* end method() */
    } /* end class */
    //~~~~~~~~~~~~
    Thanks,
    "r a g h u"
    // [email protected]

  • Event delegation model VS Listener interfaces?

    hello again,
    i got confused with "event delegation model and Listener interfaces".are both of these things are same or they are completely opposite, or they go hand in hand?
    can any body help me understand that concept.
    thanks

    event delegation would be the concept, passing out events to interested parties. listener interfaces and registering them with the event sources would be the implementation of that concept.

  • Window inheritance problem, implementation question

    This is a multi-part message in MIME format.
    --------------F5AF60803BB8EFA34C8D4288
    Content-Type: multipart/alternative;
    boundary="------------24CDBE5DFBEC0C4205C15C80"
    --------------24CDBE5DFBEC0C4205C15C80
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Hi!
    I have a window inheritance and implementation question. I'm using
    Forte 3.0.J.1.
    I have a super (base) window with a PushButton on it. I want to
    handle the Click event of the button in this super window therefore
    I create an event handler.
    <MyBtn> : PushButton
    I create a sub window inheriting from the previous super window.
    I put some data widgets on it and group all of them (the inherited
    button as well) into a GridField. When I set the mapped type of the grid
    the name of the inherited PushButton widget changes:
    <MainGrid.MyBtn> : PushButton
    When I run the application I get a SystemException with the
    message:
    Attempt to register an event on a NIL object (qqds_C_FieldWidget, 10).
    Traceback:
    SuperWindow.EH at line 0
    SubWindow.Display at line 5
    C++ Method(s)
    UserApp.Run at offset 105
    It is quite understandable that in runtime there is no widget called
    <MyBtn>
    and the event handler of the super class fails.
    But what I don't know : after specifing a mapped type of a GridField why
    changes
    the name of those widgets that haven't got mapped type e.g.: PushButton,
    PictureButton etc.
    How to solve this situation?
    I made a sall example which i send in attachment.
    Thanks for any help and advice in advance...
    Attila Racz Lufthansa Systems
    Hungary
    BUD LSYH
    E-mail: [email protected] .-``'.
    Tel.: (36 1) 431-2910 .` .' Mazsa ter 2-6.
    Fax : (36 1) 431-2977 _.-' '._ H-1107 Budapest,
    Hungary
    --------------24CDBE5DFBEC0C4205C15C80
    Content-Type: text/html; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <html>
    <tt>    Hi!</tt><tt></tt>
    <p><tt>I have a window inheritance and implementation question. I'm using</tt>
    <br><tt>Forte 3.0.J.1.</tt><tt></tt>
    <p><tt>I have a super (base) window with a PushButton on it. I want to</tt>
    <br><tt>handle the Click event of the button in this super window therefore</tt>
    <br><tt>I create an event handler.</tt><tt></tt>
    <p><tt>&lt;MyBtn> : PushButton</tt><tt></tt>
    <p><tt>I create a sub window inheriting from the previous super window.</tt>
    <br><tt>I put some data widgets on it and group all of them (the inherited</tt>
    <br><tt>button as well) into a GridField. When I set the mapped type of
    the grid</tt>
    <br><tt>the name of the inherited PushButton widget changes:</tt><tt></tt>
    <p><tt>&lt;MainGrid.MyBtn> : PushButton</tt><tt></tt>
    <p><tt>When I run the application I get a SystemException with the</tt>
    <br><tt>message:</tt><tt></tt>
    <p><tt>Attempt to register an event on a NIL object  (qqds_C_FieldWidget,
    10).</tt>
    <br><tt>      Traceback:</tt>
    <br><tt>          SuperWindow.EH
    at line 0</tt>
    <br><tt>          SubWindow.Display
    at line 5</tt>
    <br><tt>          C++ Method(s)</tt>
    <br><tt>          UserApp.Run
    at offset 105</tt><tt></tt>
    <p><tt>It is quite understandable that in runtime there is no widget called
    &lt;MyBtn></tt>
    <br><tt>and the event handler of the super class fails.</tt><tt></tt>
    <p><tt>But what I don't know : after specifing a mapped type of a GridField
    why changes</tt>
    <br><tt>the name of those widgets that haven't got mapped type e.g.: PushButton,</tt>
    <br><tt>PictureButton etc.</tt><tt></tt>
    <p><tt>How to solve this situation?</tt>
    <br><tt>I made a sall example which i send in attachment.</tt><tt></tt>
    <p><tt>Thanks for any help and advice in advance...</tt><tt></tt>
    <p><tt>---------------------------------------------------------------------------</tt>
    <br><tt> Attila Racz                                    
    Lufthansa Systems Hungary</tt>
    <br><tt>                                                
    BUD LSYH</tt>
    <br><tt>E-mail: [email protected]      
    .-``'.</tt>
    <br><tt>Tel.: (36 1) 431-2910               
    .`   .'     Mazsa ter 2-6.</tt>
    <br><tt>Fax : (36 1) 431-2977           
    _.-'     '._    H-1107 Budapest, Hungary</tt>
    <br><tt>---------------------------------------------------------------------------</tt>
    <br><tt></tt> </html>
    --------------24CDBE5DFBEC0C4205C15C80--
    --------------F5AF60803BB8EFA34C8D4288
    Content-Type: application/x-zip-compressed;
    name="Inh.zip"
    Content-Transfer-Encoding: base64
    Content-Disposition: inline;
    filename="Inh.zip"
    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
    --------------F5AF60803BB8EFA34C8D4288--

    import javax.swing.JOptionPane;
    public class Test{
         public static void main(String[] args)
              String newItem = "Item";
              float newSerial = 4234;
              float newCode = 3424;
              int newBase = 1000;
              boolean YesWarranty = true;
              boolean NoWarranty = true;
              Machinery test1 = new Machinery(newItem, newCode, newSerial, newBase, YesWarranty, NoWarranty);
              JOptionPane.showMessageDialog(null, "Item: " + test1.getItem() + " Serial: " + test1.getSerial() + " Code: " + test1.getCode()
              + " Warranty: " + test1.IncludeWarranty() + " No Warranty: " + test1.ExcludeWarranty()+ " Base: " + test1.getPrice());
    }Tested with this and it seems to be ok?
    Changed my final code too because it seemed to always add the 10% whether YesWarranty was true or false, so made it
              if (TrueWarranty==true) //There is a warranty, it returns the base price plus 10%
                   return (base+((base/100)*10));May have posted here too early if it does work, but there is another part so if ive trouble with that il be back :P
    Edited by: dave_the_bear on 16-Nov-2010 07:17
    Changed base to double and used the *0.1 method

  • How to register new interface implementation?

    Hi,
    I have the following problem:
    There exists a self written webdynpro application. This application uses a Java Interface. The administrator of the application can add new functionality to the application by adding a new line to a table. He inserts the name of a class which implements that Java interface. This class has the new functionality.
    For each interface implementation the user of the webdynpro gets a value into a list. He can select an entry from this list. This value tells to the application that it has to create an object from the related java interface implementation.
    Now I wonder how I can tell to the webdynpro application that it knows all interface implementations which will come in the future? If I do not "register" or reference the new interface implementations, then I think the webdynpro application has ClassNotFound errors.
    The developers should make there own projects for each interface implementation an deploy them. But what must be done, that the webdynpro application knows them?
    Can you please give me some suggestions?
    Thank you and best regards,
    Marcus

    You can register a Mac, but not an accessory like the Time Capsule. Keep a copy of your sales receipt.....just in case.

  • Designs for interface/implementation factory APIs

    I've been building a complex data store for geographical information based on JNDI.
    The store is basically working but I've been trying to make the API for programs accessing it more regular.
    I'm dissatisfied with the way that new objects for addition to the store are instanciated. It's all a bit ad-hoc at the moment so I want to create a proper factory system, separating interface from implementation and allowing for the case where the interface has a different implentation for remote and local contexts.
    I'm thinking the best approach would be to have a single create method, probably as a member of the extended context interface.
    What I want to get is a sample of how programmers feal about different methods of passing creation parameters to such a factory method (or for that matter, to invite comments on the basic idea).
    One possibility would be as a Hashtable or Hashmap. Generic keys (like datastore path) would be defined as constants in the context or factory interface, type specific keys in the interface which is used to access the object being created.
    e.g.
    Hashtable fsCreate = new Hashtable(5);
    fgCreate.put(DataContext.PATH_KEY, "test.features");
    fgCreate.put(DataContext.FORMAT_KEY, format);
    fgCreate.put(DataContext.BOUNDS_KEY, boundaryRectangle);
    FeatureSet fs = (FeatureSet)dataContext.create(FeatureSet.TYPE_VALUE,fsCreate);Another possibility would be some kind of parameter bean, with an fundamental parameter class and different extensions for each type of object to be created.
    FeatureSetParams fsCreate = new fsCreate();
    fsCreate.setPath("test.features");
    fsCreate.setFormat(format);
    fgCreate.setBounds(boundaryRectangle);
    FeatureSet fs = (FeatureSet)dataContext.create(fgCreate);The Hashtable method has a slightly clumbsy feel, but it does avoid directly instanciating a whole bunch of new concrete classes (which seems to go against the spirit of interface/implementation separation).

    If there's a create method in the interface, wouldn't
    that make it accessible from anything that knows about
    the interface? This would nullify the factory
    pattern, wouldn't it?Not necesasrilly, that would depend how the create method was implemented. I already have a "retriever" object associated with each implentation class that can be retrieved from the data store. I can add a "create" method, effectively adding a factory class function to these. These retrievers are already registered with the concrete implentation of the JNDI Context.
    Granted the implentations are in several different packages, so I can't restrict acces to these retriever objects to the package level.

  • Setting of listener interface to any abnormal image

    I would like to know is there is a way to set the listener interface to the abnormal images i.e for circles, half circles other than squares/ rectangles since they are default.

    Offcourse its possible.. but tells us something more.. about how are u adding images.. to your program.. are your images off-screen image.. or you have made it component?
    its difficult to say anything from information you have provided.. better you paste some lines of code..(using formatting tags).. !!

  • Which Event Listener interface is used to handle the events

    Hi!
    which Event Listener interface is used to handle events that occur when an attribute is added or removed from the Application Servlet context?
    1.Servlet context Listener
    2.HTTP Session Activation Listener
    3.HTTP Session Listener
    4.Servlet Context Attribute Listener
    Thanx

    I guess you can find that out using google.... it would be fast and easy...

Maybe you are looking for