Is there a potential slowdown when using too many listeners?

In the program I am writing, I will have at least 64 JButtons. Would it be better to write one ActionListener or 64 of them, one for each? I don’t think I'm going to use one listener for each JButton route, but it made me think about something. Is there a point at which too many listeners can harm performance, and if there is such a thing, how long will it take?

+4
source share
2 answers

I wouldn’t be so worried about this. The logic in one listener bothers me. It can become quite complicated and tired. Overhead of maintenance can be troubling. (But I have no idea what would be in this big listener.)

The small listener is focused and clearly conveys the intention. But I agree 64 is a lot.

+1
source

Each JButton is going to store a list (or an array, or a collection, or, nevertheless, it is implemented) of links to its listeners, unaware of listening to other buttons. When an event occurs, the button calls its listeners. Thus, many listeners for other buttons will not slow down the call of listeners. Thus, there is no slowdown here.

, , - . .

. - -, , .

: . , . .

+1

All Articles