Questions tagged [event-handling]

Event handling is a coding pattern related to acting on messages between a source and one or more subscribers. A point listener in the source provides a way in which subscribed code can consume messages raised from the source.

Filter by
Sorted by
Tagged with
5
votes
2answers
2k views

Java MVC model for large scale GUI using annotations

I'm trying to make a good MVC model using annotations, which I will use it in a large scale GUI project. I want to respect the maximum of rules and guidelines, and be able to decorrelate every parts ...
3
votes
1answer
131 views

UpdateGame function for Tetris

I am writing a Tetris game while learning Haskell and I'm trying to make the following code more concise and easier to read. How can I improve it? Note that the function is not finished yet (There is ...
6
votes
1answer
2k views

ECS Event/Messaging implementation

I am experimenting with ECS design and I am looking for a solid way to implement a message bus for use between the different systems. Here is a stripped-down version of my current implementation: <...
2
votes
0answers
273 views

handle drag and drop operations

I've come up with the following code to handle drag and drop operation. It's composed of a constructor function that returns an objects with methods to attach to event handlers. Notes about this ...
7
votes
1answer
501 views

Custom event hub

I'm creating an event hub object in for a large project I am building in JavaScript. The project will have modules in charge of the UI, commands, and rendering. Each module will use this hub for ...
5
votes
1answer
2k views

Copy Cell on Worksheet_Change event if some criteria is met

This code is working fine, but it looks awful (yes, I am a rookie on this thing). How can I improve it to look better? ...
1
vote
1answer
67 views

Repetitive event handler for a toggling UI control

I feel like this bit of code could have been written more elegantly, especially with the huge if/else statements. Can somebody help me break this down? It would really help me out in the future. <...
6
votes
2answers
418 views

Is my Delegate defined the right way and does it need to transform to a pretty Event butterfly?

I have read so many bed time stories and ins and outs of how delegates work and why events are to be replaced with delegates (surely not all the time) and just couldn't get my head around it. I am ...
3
votes
1answer
6k views

Inactivity Timeout

I made this piece of code to detect inactivity on different aspects of my app. It is part of a set of pieces to analyze user behavior. Not saying it's ugly, but good looking constructive criticism to ...
3
votes
1answer
2k views

Invoking only the last registered event handler

We are building a game and we have a dialog system. Dialogs may open and stack on top of one another. When every dialog opens, it registers itself to handle the BackButtonPressed event: ...
5
votes
1answer
2k views

Closure as UIControlEvents handler

I'm expanding the functionality of this SO answer. Mainly I'm focusing on: You can add as many handlers as you want. You can remove (i.e. cancel) the handler. You can receive the ...
5
votes
1answer
84 views

Synchronization Event with awaitAny

In Java, there is no way I know of to wait for multiple events at the same time (see Stack Overflow). Since I would like to use that feature (similar to ...
4
votes
1answer
2k views

Asynchronous API calls with delegates and event handlers

I'm making a WindowsPhone 8 app in C#. With this an API so I can convert JSON data into useful objects. I've found a method but am wondering if it is any good at all. The problem is it's been a while ...
1
vote
1answer
48 views

Adding classes with JavaScript

I am working again and got this to work. Is this the best way to write this code? ...
2
votes
3answers
223 views

Loop termination check for multiple types of host reachability tests

I have 2 booleans: host.isReachableOnLan, and host.isReachableOnWan I have a listener ...
2
votes
1answer
122 views

Many onClick handlers that all append different text to one textarea

The script basically just appends the words based on the user's click/s on the textarea. I just need some help improving my code further using the ...
2
votes
1answer
2k views

Using a List to manage Swing event listeners

I've been playing with an idea for simplifying management of event listeners on custom Swing components. Swing provides the EventListenerList class for maintaining events, and every JComponent has a <...
8
votes
1answer
2k views

Animations when navigation items are clicked

I'm a beginner in jQuery and am wondering how I could write the following code shorter, since I'm repeating a lot. Working example ...
4
votes
3answers
585 views

Click handlers for two to ten buttons

I have click event handlers for two buttons. The code is working well, but I want to apply the DRY principle. How should I rewrite the following code in the button_click event handler so that I don't ...
2
votes
1answer
94 views

Detaching logic from listener implementation in “Smart UI” approach to follow a proper pattern

I took this code segment from existing source on Android, but it applies to anything from ASP.NET Forms to anything else where the UI has an event callback, and the logic is implemented directly in ...
2
votes
2answers
5k views

Optimizing jQuery addclass / removeclass on scroll

I have a scroll event and add class and remove classes for different elements. As you can see the code is a bit big. Is this method ok or is there a more efficient one? I mean, you can see that there ...
6
votes
1answer
2k views

Navigation bar built from fetched JSON data

I have finally been able to create my little navigation plugin in an object-oriented way that reads the li from a JSON file. Now, is my code efficient? Especially, ...
9
votes
2answers
158 views

TestExplorerWindow, the event-tossing UI

Following up on Integrating Unit Testing functionality into an old COM-based IDE, I made quite a few changes to the UI, and now the code-behind for my ...
8
votes
2answers
2k views

Overriding all Access form control AfterUpdate methods

I have a set of custom event handlers for all my textboxes and combo boxes. The reason for this is my users want the bound form (to SQL Server) to immediately push changes to the recordset, rather ...
5
votes
2answers
1k views

Toggling between radio buttons

I have several buttons and I want to toggle between them like radio buttons. The way I have it set up now is that each button have this same code but the ...
3
votes
5answers
92 views

Handing focusing and unfocusing of multiple form fields

Here is a link to my problem ...
1
vote
1answer
2k views

Is this use of JavaScript prototype functions for attaching event listeners going to meet design goals?

Please provide a sanity check on my below JavaScript pattern to be used for a custom edit control. The goals are: Centralized code Avoid name collisions Minimize memory use (putting functions on ...
5
votes
2answers
2k views

Extension methods for safely firing events

I wrote a set of extension methods for the EventHandler class that add the method Fire, which raises the event after creating a ...
10
votes
5answers
14k views

One-shot events in C#

I have a class that performs some long-running operation. This class exposes a Completed event. I'd like clients that use this class to register to get notified ONLY ONCE when the class completes ...
3
votes
1answer
64 views

Combining four functions for toggling gallery displays

Here is my HTML: ...
11
votes
7answers
2k views

Too-high / too-low guessing game in Swing

I have created this program and it works fine. It's just that its too wonky and huge so I was wondering if anyone knew how I could shorten the program so I didn't have to put all of these into each ...
4
votes
1answer
2k views

Toggling element class according checked radio input V2.0

This question is about an improvement of the code from this previous question (previous changed visibility, new applies a CSS class with a border). It is a constructor function that attaches a click ...
6
votes
2answers
1k views

Android audio player

I want to implement basic audio functions like play, stop and pause. I have stuffed all the code inside onCreate method. Is this best practise to follow? ...
3
votes
1answer
135 views

Refactor three state button

I have a button (or icon) which can have three states. On hover, it changes state and on click, the new state gets transferred to another state. This state is kept until you click again for which it ...
4
votes
2answers
241 views

Compact jQuery tool tip code, without jQueryUI

I have this tooltip code that I came up with, using jQuery: ...
5
votes
2answers
21k views

JavaScript onKeypress validation

This is a function for JavaScript validation: ...
5
votes
2answers
205 views

Messy handler for multiple touch events in a game

I have a mobile game, utilizing cocos2d-x, that has a handler for touch events. What it does: Main function that gets the touch. Loop in module A. All sprites check if the touch coordinates are in ...
2
votes
1answer
450 views

Best way to handle tap gestures

I'm building a small web app primarily for mobile use. I have some widgets that need to handle tap gestures in the expected way, and I don't feel this one feature is reason enough to include JQuery ...
3
votes
2answers
125 views

Is this too much work for 1 listener?

Is this too much work for 1 touch listener? Is this bad for devices with slow CPU's? ...
7
votes
1answer
3k views

“Function Buffer” to avoid triggering an event handler too frequently

If some big event handler is triggered too frequently, it will cause computer lagging. In my example $(window).resize(), I want the function to be called after the ...
3
votes
1answer
216 views

Recognizing elements and doing event handling for repeating templates

This fiddle has an ADD button when you click it a Chat window is added. When there are more than 1 windows the message from one window is reflected across all the windows. Say you have templates (in ...
18
votes
5answers
6k views

Using sounds in Java

I'm trying to apply sound today, and the goal in mind was a simple violin tuner. The actionListener seems repetitive/ How might I optimize it (what I tried just ...
1
vote
2answers
2k views

Menu selector that changes the background of a selected div

I made this code to change the background color for a div in a set of divs while disabling the rest of the ...
-1
votes
1answer
47 views

Touched events created in a for loop [closed]

All I want is a simple "yes/possible" or "no/and that's bad coding". I have a card game I'm making and looking through your discard pile is a big part of it, so it's going to be constantly growing. ...
6
votes
2answers
194 views

Scroll listener - about code style guidelines and standards

I'm an upstart, been only professionally programming for a bit less than 2 years, mainly in Java as I am currently working as an Android developer. I often find myself thinking about how to improve ...
6
votes
2answers
833 views

Small jQuery mobile plugin to handle touch events

Why this plugin: I am developing a mobile app - at some point, I felt like this would be a good idea to give the users the possibility to control everything in the app with touch gestures, hence the ...
0
votes
3answers
533 views

Does this function have to be nested?

Recent JavaScript student here. I ran afoul of some weirdness with event listeners that led to my code being unresponsive. After some reading and tweaking, I arrived at a version that worked in ...
4
votes
1answer
1k views

Possible memory leak with WPF Custom Control?

I might have a potential memory leak with my custom control. Do I actually have one? ...
2
votes
2answers
1k views

Creating a function when user clicks on element to toggle another element

I use a lot of "when user clicks on element then another element will be displayed as visible/hidden... aka toggle". So I'm trying to make a general function to abide the DRY principal. Before ...
3
votes
1answer
4k views

Enabling/Disabling button on a certain condition

I am using a Telerik Datetime control. On onBlur event of input box I am checking if the date is valid/in-valid, based upon that ...

1
5 6
7
8 9