Reputation: 1415
For educational purposes, I am building a MIDI piano applet in Java. For that I want to:
What is the best way to implement key listener satisfying the above criteria?
Having only two key listeners (for key press and release) or having key listener per key?
Upvotes: 0
Views: 129
Reputation: 718708
Having only two key listeners (for key press and release) or having key listener per key?
Neither. I think you need a single listener that handles both key press and key release events ... for all of the keys. Each event includes a when
attribute that you can use to compute how long a key was held down.
Finally, note that applets are now deprecated technology, so the educational value of doing this is limited, as is the practical value of the code you write. Most browsers removed all Java plugin / applet support some time ago.
Upvotes: 1