I'm trying to make a program that will toggle a boolean value and paint a red rectangle on the right side of a swing panel when you press the 'a' key. Unfortunately, I'm not having much luck, because when I hit 'a' nothing happens. My mistake is probably something obvious that I'll know how to fix once someone points it out for me, but for the life of me, I can't find it. If someone could look over my code and figure out what's wrong, I'd very much appreciate it. I've attached my source code below.
nocookies92 0 Newbie Poster
Recommended Answers
Jump to PostRe-read NormR1's second question and check your code again.
are they connected to any components?
Jump to PostYou must add the KeyListener to a component with the addKeyListener() method. It's similar to what you did with the ActionListener for the buttons.
Implementing the interface just defines what the listener does. Then you attach it to the component you want to listen to.
All 8 Replies
NormR1 563 Posting Sage Team Colleague
nocookies92 0 Newbie Poster
NormR1 563 Posting Sage Team Colleague
nocookies92 0 Newbie Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
nocookies92 0 Newbie Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
nocookies92 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.