Create generic event listeners

I am trying to create generic event listeners {That should respond to mouse click, keyboard whether it happens on a frame, menus or command line }.
Is it possible??

It is not strictly speaking a listener, but you could override Component.dispatchEvent() to capture all events in one place.

Similar Messages

  • Help me I'm trying to create event listeners

    I am trying to create event listeners
    Whenever any keyboard event occurs the string s gets appended by a,c
    or p.At the end of the program its supposed to print value of s
    But s always happens to null.Please tell me how to correct it....so
    that detection is possible for any case
    import java.io.*;
    import java.awt.event.*;
    public class trial {
    int x;
    public static String s;
    //OutputStream f1=new FileOutputStream("file2.txt");
    public static void keyReleased(KeyEvent e)
    s=s+"a";
    public static void keyPressed(KeyEvent e)
    s=s+"c";
    public static void keyTyped(KeyEvent e)
    s=s+"p";
    public static void main(String args[])
    throws IOException
    char c;
    BufferedReader br =new BufferedReader(new
    InputStreamReader(System.in));
    System.out.println("Entercharactes,'q' to quit.");
    do
    c=(char)br.read();
    System.out.println(c);
    while(c!='q');
    // for(int i=0;i<s.length();++i)
    System.out.println(s);

    I suggest looking at the java tutorial. Your code completely misses the mark and you need to see examples.

  • Creating custom event listener ?

    Hello,
    Is there anyone that have a link to a tutorial or have some information on what is needed to be able to create a custom event listener on a component ?
    I am creating an interactive JSF chart library (JSFlot) and I would like to have events such as ChartDraggedEvent and ChartClickedEvent. I can create the events fine (and I can even queue them fine throught the standard action and actionListener interfaces), but I would like for the component to have attributes like chartDraggedListener and chartClickedListener, so that I can fire off the appropriate event to the appropriate listener.
    Any help would be very much appreciated!

    Well, that is what I am doing. The Renderer:
    if (event != null && event.equalsIgnoreCase("drag")) {
                        String componentValue = request.getParameter("componentValue");
                        //Cut out logic irrelevant for this example
                        FlotChartDraggedEvent dragEvent = new FlotChartDraggedEvent(component, dragValue);
                        dragEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
                        dragEvent.queue();
                   } else if (event != null && event.equalsIgnoreCase("click")) {
                        //Cut out logic irrelevant for this example                    
                        FlotChartClickedEvent clickEvent = new FlotChartClickedEvent(component, clickedPoint, clickIndexInt, clickSeriesIndexInt, clickSeriesLabel);
                        clickEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
                        clickEvent.queue();
                   }The problem though, is that both of these events gets delivered to the actionListener attribute of my component. What I assume is missing is functionality to register a custom listener for each event, and some code in the Tag-class and TLD to supply these listeners, and its these issues that I am unsure how is done. I may be missing something very basic here though :)

  • Event Listeners VS Event Functions

    I'm working on a new project at work where there's lots of
    custom objects with lots and lots of event listeners. I keep
    finding myself saying, "why didn't they just use the built in
    objects with built in event handling?". However, from what I can
    see it seems like AS3 leans heavily towards using Event Listeners
    as opposed to putting event responsibility on the object itself
    (E.G. XML.onload). Is there an advantage to this (other than making
    it more Java like?) I've always favoured keeping the responsibility
    on the object itself because it seems like one less object to keep
    track of and also makes things feel more self contained. If I have
    10 objects that fire 10 different events, I have to create 10
    different event handlers (or 10 different case statements within
    the same event handler), whereas with self event handling, I just
    code in the event function.
    Anyways, I wanted to open discussion to which method of event
    handling you prefer and why, and also what you believe the
    advantages to this. I was searching google for previous discussions
    on this but I couldn't seem to find anything, so I thought I'd get
    the ball rolling! Looking forward to reading these, try not to be
    too elitist in your posts!!

    I tried to change getFileOperation to getFileOperation2 in one of the functions as follows but same problem appeared.
    function f3 (event:MouseEvent):void
    trace("f3 triggered");
    getFileOperation2.addEventListener(ResultEvent.RESULT, f4);
    Do you have an idea how I can avoid the same function from triggering twice?? thanks a lot

  • All event listeners and models in one file?

    I have one java file for all my event listeners of a programm and one java file for all my models. Is this good?
    I create instances with new AllInOneHandler.MouseHandler() for example.
    Or should I have one file for each event and each model?

    Hi,
    you should have one file for each class or interface - this gives you best control and reusability. Also when you have javadoc-comments in it, big files with many classes in it will become hard to edit.
    When using one file for each class or interface you can import only the needed classes or interfaces instead of importing whole packages - so it is easier to see, what is exactly imported. As so a good structured application has many classes, where each of them is small (and in an own source file), you will have less problems during the evolution of your classes this way.
    If you want to group some classes, why not use sub-packages for this purpose?
    greetings Marsian

  • Multiple Event Listeners

    Is it possible to have event listeners apply to multiple objects, instead of creating multiple functions?
    I'm just wondering if there is an easier way than making a new function for the same event listeners for each object I want to apply it to.  Here's my code thus far, just to clarify what I'm talking about:
    import gs.*;
    var mc_homeX:Number = mc_home.x;
    var mc_productsX:Number = mc_products.x;
    var mc_msdsX:Number = mc_msds.x;
    var mc_environmentX:Number = mc_environment.x;
    mc_home.addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
    mc_home.addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
    function onOver(e:MouseEvent):void
         TweenLite.to(e.target, .2, {x:mc_homeX-10});
    function onOut(e:MouseEvent):void
         TweenLite.to(e.target, .2, {x:mc_homeX});
    I've only starting adding the listeners to mc_home, but I'd like to apply them to all.  Any help would be appreciated.  Thanks.

    import gs.*;
    var mc_homeX:Number = mc_home.x;
    var mc_productsX:Number = mc_products.x;
    var mc_msdsX:Number = mc_msds.x;
    var mc_environmentX:Number = mc_environment.x;
    var mcA:Array=[mc_homeX,mc_productsX,etc];
    for(var i:uint=0;i<mcA.length;i++){
    mcA[i].addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
    mcA[i].addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
    function onOver(e:MouseEvent):void
         TweenLite.to(e.target, .2, {x:mc_homeX-10});
    function onOut(e:MouseEvent):void
         TweenLite.to(e.target, .2, {x:mc_homeX});
    I've only starting adding the listeners to mc_home, but I'd like to apply them to all.  Any help would be appreciated.  Thanks.

  • Does removeChild remove the object's event listeners?

    Hi
    If you dynamically create a parent movieclip, and dynamically add a color picker to each clip, and add an event listener for each color picker, does a removeChild on the parent movieClip remove event listeners belonging to any of it's children?
    Thanks
    Shaun

    Ahh - thanks Ned
    Is there any software you could recommend that monitors and shows you what or how many event listeners are open, memory consumption etc, to help you to trim the fat from your coding?
    Thanks
    Shaun

  • Generic event controller

    Hi!
    I want to implement a generic event controller. For that I defined the Event interface
    public interface Event{
    }and the EventObserver interface
    public interface EventObserver<EventType extends Event> {
        notify(EventType event);
    }Now I wrote the following event controller:
    public class EventController {
        private Map<Class<? extends Event>, Collection<EventObserver<? extends Event>>> mapping = new TreeMap<Class<? extends Event>, Collection<EventObserver<? extends Event>>>();
        private EventController instance;
        // Singleton.
        private EventController() {
        public static EventController getInstance() {
            if (instance == null) instance = new EventController();
            return instance;
        public <EventType extends Event> void registerForEvent(Class<EventType> eventType, EventObserver<EventType> observer) {
            if (!mapping.containsKey(eventType)) {
                LinkedList<EventObserver<EventType> observers = new LinkedList<EventObserver<EventType>>();
                mapping.put(eventType, observers);
            mapping.get(eventType).add(observer);
        public void fireEvent(Event event) {
            if (mapping.containsKey(event.getClass())) {
                for (EventObserver<? extends Event> observer : mapping.get(event.getClass())) {
                    observer.notify(event);
    }Sadly this code does not compile. The compile problem is in the fireEvent method in the line observer.notify(event). It is not clear, that the generic type of the returned observer fits that of the actual event.
    The real problem in my opinion lies a bit deeper and is: You can have generic methods and force the types of the method's parameters to fit together but you can not have generic member variables. If you could, I could force the type of the keys of my mapping to fit to the type of the added values (which are in this case the observers).
    Of coure I could distinguish between every event type manually and have a list of observers for every event. Or I could have just one list, add all the observers to it and notify every observer in case of all events. Then the observer would have to find out if the event was the one it actually wanted to be informed about. But I think all these solutions are not really good design. So can anyone think of some clean generic solution that maps events via their type to the corresponding observers?
    That would be great! :)
    Best regards!
    Erki

    You can have generic methods and force the types of the method's parameters to fit together but you can not have generic member variables.Hello!
    U are right.
    But u can otain it by casting.
    import java.util.Comparator;
    * Allows create comparator for Comparable objects without knowing anything about comparing this kind of objects<br />
    * For additional allows put null in begin of order without {@link NullPointerException}
    * <p />
    * Multithread safe.
    * @author Marek Kozie&#322;
    public class ComparatorNatural<Level extends Comparable<Level>> implements Comparator<Level> {
      protected ComparatorNatural() {
        super();
      @Override
      public int compare(Level o1, Level o2) {
        if ((o1 == null) || (o2 == null)) return (o1 != null ? 1 : 0) - (o2 != null ? 1 : 0);
        return o1.compareTo(o2);
      @SuppressWarnings("unchecked")
      private static final ComparatorNatural  comparator  = new ComparatorNatural();
       * Multithread safe.
      @SuppressWarnings( { "unchecked", "cast" })
      public static <Level extends Comparable<Level>> ComparatorNatural<Level> instance() {
        return (ComparatorNatural<Level>) comparator;
    }And now to use it u need:
    Comparator<String> comparator=ComparatorNatural.<String>instance();I do not have much time now, so pls tell me if this fits u's need.
    Greetings

  • Not able to create an event in month view of iCal?

    I used to be able to create an event from the month vien of iCal, and it doesn't work anymore. Anyone knows how to fix this?
    Thanks

    So sorry to not have a solution but I wanted to chime in and say "me, too!". Not only create an event, but I can't edit it in month view, either. I thought it was my entire iCal program, since I just upgraded to Lion today, but after reading your post I realize I can edit events in week mode, just not month mode.

  • Error while creating a Event in Table maintanence gen

    Hi,
    I've created a table maintanence gen every thing worked fine...i wanted to create a event 05 at new entries in my table main gen so i did it and wrote a subroutine inside it without any logic since i thougt of doing it later and just saved it and came out out the event creation......Now when i want to go to same even the its pops up a Information error which says 'Function group  zxyz cannot be processed.' I cant open any thing from the main menu of the screen...like from environment or from utilities...for every thing it pops up the same message....is it bcoz of the event which i've just created......if i still want to delete it...its not allowing me to go into the event again..how to do it guys...suggest me
    Thanking you.........

    Hi Younus,
    Check whether the function group u created is ACTIVE or not.
    Go to se80. Give the FG name.. check it. Check all the includes in the Function Group whether they are ACTIVE or not.
    Try checking the Package in the TABLE MAINTANCE GENERATOR screen. Assign the Function Group to the correct package.
    I think this solves the issue.
    check the FG name in display mode in the TMG.
    Regards,
    Priyanka.

  • How do I create an Event Handler for an Execute SQL Task in SSIS if its result set is empty

    So the precedence on my entire package executing is based on my first SELECT of my Table and an updatable column. If that SELECT results in an empty result set, how do I create an Event Handler to handle an empty result set?
    A Newbie to SSIS.
    I appreciate your review and am hopeful for a reply.
    PSULionRP

    Depends upon what you want to do in the eventhandler. this is what you can do
    Store the result set from the Select to a user variable.
    Pass this user variable to a Script task.
    In the Script task do whatever you want to do including failing the package this can be done by failing the script task, which in turns fails the package. something like
    Dts.TaskResult = Dts.Results.Failure
    Abhinav http://bishtabhinav.wordpress.com/

  • How to create the event in the report for jobs scheduling.

    Hi Experts,
    i have a requirement like as follows:
    The following triggers for Batch Jobs in the SCM system will be created.i.     
    Background Processing Event = u201CAPO Background Processing Eventu201D. After sending the Event, write a Log Report line u201CEvent u201CAPO Background Processing Eventu201D sentu201D.
    Could you please suggest me how we create the Event or which transaction ?
    Please give me a steps for creating events so that based on these events we use
    CALL METHOD cl_batch_event=>raise
        EXPORTING
          i_eventid                      = p_bpeve
          i_server                       = p_server
          i_ignore_incorrect_server      = p_ignore
        EXCEPTIONS
          excpt_raise_failed             = 1
          excpt_server_accepts_no_events = 2
          excpt_raise_forbidden          = 3
          excpt_unknown_event            = 4
          excpt_no_authority             = 5
          OTHERS                         = 6.
    Right now i received message "APO Background Processing Event" is doesn't exists.
    Thanks in Advance.
    Puneet.

    Hi Puneet,
    Goto transaction SM62 and in there to BckProcEvents tab. There you can create the events.
    You just need to specify the name and Description of an event.
    Hope this serves your purpose.
    Thanks

  • How to block execution of event listeners

    Hi all,
    JDev version : 11.1.1.6
    My requirement is that I want to block all event listeners like ActionListeners, SelectionListeners, DisclosureListeners, RowDisclosure listeners when the screen is opened in readonly mode.
    I could block ActionListeners by disabling command links and command buttons etc.
    But there's no way to block SelectionListeners, DisclosureListeners, RowDisclosure listeners.
    So Is there any common code which can block all listeners?
    Or is there any EventController or something like that which will allow me to control event execution?

    I would have if it was just one screen.
    There are hundreds of screens.
    Anyways, can't I use any javascript to do this? There are some interfaces like EventListeners , classes like EventConsumer etc. Do none of them provide feature to block event listeners?

  • Creating Business event in training and event management

    Hi Gurus!!!,
       can you please instruct me the steps involved in creating business events in Training and Event Management.(HR Module)
    Thanks and regards,
    Prosper

    Hi Prosper,
    You need to configure lot of settings, prior to Business Event, because one BE is based on various elements like Location, Attendee type, Instructor, Fees, Resources, Time Schedule, Services, BE type, BE Group.
    After configuring all these for BE type, you need to create a BE for the BE type. Then, you can go for day to day activities like Booking, Pre Booking, Cancellation.
    I hope, this link will help you
    http://help.sap.com/saphelp_47x200/helpdata/en/26/865738c185f50ce10000009b38f8cf/frameset.htm
    Good Luck
    Om
    Reward it, if u feel helpful.

  • I can no longer create an event on iCal by double clicking on a time or date, nor can I double click on an existing event! HELP!

    I can no longer create an event on iCal by double clicking on a time or date, nor can I double click on an existing event! HELP!
    The only way I have to create an event is by using the "+" button, which is very limiting!
    I am running the latest version of Mac OS X and all the updates.
    Anyone know how I could get a proper use of my iCal ?
    Thanks

    Hi,
    If you list the steps you have taken to fix this it will help.
    Have you tried using the File > New Event menu item?
    Have you logged the user account out/ restarted the computer?
    Have you tried un-syncing any accounts synced to Calendar?
    Is there some change made to the computer that may have triggered this?
    Best wishes
    John M

Maybe you are looking for