I've been have difficulty with KeyListener
(not detecting keys) and I'm trying to switch over to KeyBindings but JFrame
doesn't extend JComponent
which is needed for the getInputMap() function. Any ideas?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Use a surrogate
JComponent
instead. For example, set the frame'scontentPane
to be aJPanel
and use it to register the key bindings.This is a very basic example, which uses a
JPanel
as thecontentPane
and adds aCanvas
to it. The key bindings are then registered through theJPanel
on behalf of theCanvas
which is actually used to respond to them.This example only override's the
Canvas
spaint
method, but the concept should still work for implementations usingBufferStrategy