Skip to content
Advertisement

Tag: keylistener

Highest performance for Keyboard Input

So I have a small java game engine using a single JFrame. I am currently using Key-Bindings as they were working neatly but I figured that a KeyListener might be architecturally more fitting. But since I honestly don’t really care which I’ll use I wanted to ask if there is a performance difference between these or even a better option

Referencing from an inner class

I have the following code My aim here is to create an array of JTextFields which have a keylistener on. This keylistener should prevent anything other than numbers being entered in the JTextField. It should also change the color of the JTextField’s background if the number entered is not an int. For example 2147483647554. However when I compile this I

Having Listener in new Thread

I’m trying to place my KeyListener in a new Thread called Keys in my project because my main thread is already in a loop. So I want this method to return a boolean if the key is pressed or not. I’m pretty new to Java so sorry if that is just a dumb mistake. Thread: I would appreciate an example.

Advertisement