How does KeyListener work?
I have two(relevant) classes which ive made trying to figure out how this works.
21 Replies
⌛
This post has been reserved for your question.
Hey @blockgoblin31! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Running prints and the window is created but after that nothing else happens
most of this is me trying random stuff from the tutorial linked from the KeyListener page on the oracle docs
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Ive done that
frame.addKeyListener(game);
line 18 of the first giant code blockUnknown User•12mo ago
Message Not Public
Sign In & Join Server To View
yes, that line is called(the println for "running" works), but none of the other printlns ive scattered around work
say the one in keyTyped
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
It also didn’t work when I didn’t have any other components
Just the jframe and keylistener
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
so what here would be focusable?
I tried adding the listener to the JScrollPane and JTextArea too
in the example they added it to a JTextField, which makes sense I guess though I thought I tried that and it didnt work
ok when I do that it works now... Is there a way to get it to work without needing a textbox?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
I've been looking at that, when I said "the tutorial" I meant the file linked at the bottom there
and I dont understand how I'd convert an Action into code somewhere else with key bindings, or what an Action is really
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
ok thanks I'll try that out, but tomorrow, Ive done too much coding already today
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
so I've now tried doing it with keybindings, which is way nicer, but I can't figure out why one keybind works and the other doesnt
so with this the first action works but the second doesnt
I've confirmed with debugger only the first one is getting triggered
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
oh yep that was it, worked fine with b
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Maybe thats left alone because the focused component is a textbox, so it uses copy instead of passing it on
either way ty again
Post Closed
This post has been closed by <@501514065068294154>.