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
17
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 ...
17
votes
2answers
28k views

Generic EventArgs to go with generic EventHandler?

There is as of .NET 2.0 a generic EventHandler delegate type, which can be used to define an event in terms of the EventArgs ...
15
votes
2answers
2k views

Using events together with interfaces in VBA

Introduction Because of the limitation of VBA in using events in interfaces I was searching for a kind of workaround. For sure I also read this which also provides an approach, but I was searching ...
13
votes
1answer
5k views

My Event-handling system

I have written about 180 lines of code that implements an Event system. I would like a general review about the code and I'd love comments about the usability of it. (Is the code useful? Would you ...
13
votes
1answer
23k views

Click event function that checks to see if form field is valid

What I'm building is a URL builder. A marketing person inputs a URL and can test that URL to see if it's valid, then they select a demand channel and then hit 'Generate Campaign URL'. I've omitted the ...
12
votes
1answer
25k views

Use of Async/Await for EventHandlers

I have a MVC WinForms application. I am using Dependency Injection with Ninject as the IoC container. ...
12
votes
3answers
4k views

Simple event management system

In an effort to rid my code of jQuery, I wrote a custom global event management/handling system. I was expecting this to be hard as, from what I've read, most people don't create their own. It's far ...
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 ...
11
votes
2answers
6k views

Event Listener and Publisher

This is my first attempt at creating an event system. My plan is that upon publishing, the listener receives both a reference to the model and to the publisher. This allows the publisher class to ...
11
votes
1answer
2k views

C++14 Event System

I've created a simplified event system for C++14. The code is commented, so it shouldn't be hard to read. There's also a simple usage scenario below. It is still a work in progress and uses some not-...
10
votes
5answers
13k 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 ...
10
votes
1answer
578 views

Finger painting code

I have a very simple view that handles touch events and draws accordingly. It's nothing significant, but it does use a bit more CPU than I would like (35%). Again, it is the bare minimum (<90 lines)...
10
votes
2answers
397 views

In memory data access for CSV files that may have changed

I'm reading data from CSV files and store the result in a simple DataContext instance that gets injected throughout my application. ...
10
votes
0answers
205 views

Windows keylogger in C++

Windows keylogger in C++ Known issues: Not implementing rule of five Having to use hack to use member variables, out_, in static method Pressing caps-lock won't ...
9
votes
2answers
157 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 ...
9
votes
2answers
424 views

Dynamic network messaging

I'm building a client and server for a game but wanted a generic messaging system in a shared library that let me focus on application logic and was largely separate form the underlying networking I/O ...
8
votes
3answers
799 views

Fourteen buttons with hover effects

I have just started learning coding and am trying to clean up a website that I am making. Everything is functional, but I imagine there is a better way write everything that is there, because a good ...
8
votes
4answers
504 views

Making an Action<T> event also usable as Action<object> and Action in C#

Edit I've added a second pass at this problem based on the answers that have been posted by other users so far: https://codereview.stackexchange.com/a/221525/75659 Context Before presenting the ...
8
votes
2answers
3k views

WinForm Calculator

I'm looking to get this cleaned up. ...
8
votes
1answer
2k views

How can I condense several IBAction methods in a class with a delegate?

I have the following class: MyProtocolClass.h ...
8
votes
3answers
943 views

Mask latitude text field

I have an input element on one of the pages. This input is supposed to take a string of digits from a user. In order to enhance UX I'd like to mask input's value at any given time. Like so: What came ...
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 ...
8
votes
2answers
1k views

Javascript typehead using debounce

This is the code I wrote for making a JavaScript typeahead/autocomplete, which displays cities based on the user input. It would be great if you could suggest some improvements on the code quality. ...
8
votes
2answers
2k views

Recorder for keyboard and mouse events

I'm building an event recorder. So far the code looks clean, but I feel like I'm missing something that can make this code even better. Is composition a better solution? If yes, how can I do it ...
8
votes
0answers
401 views

Simple, intuitive and (hopefully) safe EventDispatcher

For my own game engine I need an event system. I tried to avoid the single-huge-enum-approach for minimizing compile times. The BasicEventListener is the (...
7
votes
2answers
3k views

Updating dimensions when focus is lost from any of 9 columns

How can I write this more pretty? ...
7
votes
3answers
198 views

Downloading files from a Mozilla file server via FTP

All classes on GitHub repo This is the code for downloading files from a FTP-server running Mozilla Fileserver. FtpItem is the interface for the two classes ...
7
votes
2answers
1k views

JPaint (Java painting app)

I have this painting app called JPaint in Java and I'm wondering if it could be improved. The variable declaration seems repetitive and long, and I think it might ...
7
votes
3answers
200 views

Notifying the UI that Issues Were Found

Our Rubberduck VBA IDE Add In does some static code analysis, and then reports all of the found issues back in a gridview. This analysis can take a long time for larger projects and the UI appeared to ...
7
votes
2answers
6k views

Yet another event dispatcher in c++11

I've written an event dispatcher for a private project which task is to collect events from different threads and dispatch them in a single thread: ...
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 ...
7
votes
1answer
1k views

Even handler for text input preview

In a WPF application I have the following event handler for PreviewTextInput event in ComboBox control. The main purpose of this ...
7
votes
2answers
807 views

Drag and drop single files on different targets for different purposes

I have three text fields (DevExpress ButtonEdits set to read only) on a Windows Forms app. They look like this: They're used by dragging and dropping a single ...
7
votes
1answer
124 views

Detecting two keys pressed in quick succession

My computer has been having this issue where when I press a key, two key presses get registered. The goal of this program is to detect the time delta between the two keys so that I can set an ...
7
votes
1answer
174 views

My EventBus system

I decided to roll out my own EventBus system which is intended to be thread-safe. Hence a review should focus extra on thread safety apart from all regular concerns. The ...
7
votes
1answer
5k views

Event Handling system in Java

I have written a system for handling the dispatch of events between objects. (I need this functionality for a larger project I am working on. Objects should be able to dispatch events without knowing ...
7
votes
1answer
2k views

Event dispatcher / listener

I'm working on a program that will be significantly multi-threaded. I need to respond to events between objects and threads so I've come up with the following code. ...
7
votes
1answer
481 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 ...
7
votes
1answer
157 views

Threadsafe oneshot-event which fires on subscription if the event was fired in the past

Assumptions Basically, a Connection class has a "Disconnect" event. Subscribing to this event isn't thread-safe, because the disconnection may fire from another thread right before I subscribe. So ...
7
votes
0answers
2k views

Implementing my own signal slot mechanism using C++11

I programmed in C# and I used the Qt framework. Both of them have their own signal slot mechanism which are really powerful. I looked at several implementations in C++ and based on what I learnt from ...
6
votes
2answers
949 views

Type-Safe Event System

I have recently started writing C# from a strong JavaScript background, and found myself wanting to do something I do all the time in JavaScript: events. Since I have a type system at my disposal, I ...
6
votes
3answers
4k views

Mouse input handler which exposes read-only mouse state data

I have a MouseInputHandler class that registers itself to an InputManager. When the InputManager class receives events they are ...
6
votes
2answers
992 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? ...
6
votes
2answers
767 views

Python Event Dispatcher

This code creates a singleton event dispatcher. It's called like this: ...
6
votes
2answers
160 views

My EventBus system followup

This question is a followup from my previous question My EventBus system, and incorporates most points from @rolfl's answer. It includes, but is not limited to: Usage of ...
6
votes
2answers
224 views

Tic-Tac-Toe code in JavaScript

I have developed a tic-tac-toe game in native JavaScript. Can you tell me how to optimize more and what are the missing things? JSBIN The logic, modular approach, testable and scalable? ...
6
votes
2answers
193 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
406 views

Shopping cart using events and delegates

I am trying to learn events and delegates in C#. To do that I am trying to create a hypothetical console project where when some user submits the orders in his/her shopping cart, I need the Billing ...
6
votes
1answer
1k views

Simple implementation of signals and slots mechanism using templates

I tried to implement a simple signal&slots mechanism for some DSP software that runs on embedded Linux. I would like if somebody can review this code and give me some guidelines. Any review and ...
6
votes
1answer
299 views

Custom Event System in C#

I'm currently writing a game and want to encode everything that happens (GameObject has moved, hp changed, was created/destroyed, got/lost a component, ...) in Events that look like this: ...