Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

keys in a swing-application  RSS feed

 
hugo egon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've the following question:

How can I use keys to controll sth in a java-program

If someone of you could help me it would be very nice

thank you!!!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is sth?
 
hugo egon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Panel on witch I drawed a oval.

I want to change the position of the oval in the Panel.

My goal is to do this with the arrow-keys.

My problem is that I don`t now how to listen the event from this keys.

So if you understand now what's my goal pleace give me a answer for my

problem. If my English is so bad that you don't understand it again please

ask a second time.

Thank you
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not that your english is bad. I just didn't know what sth was.

Take a look at the Swing Key Listener Tutorial from sun. Note that what you will want to do is create a class that extends JPanel and override the paintComponent(Graphics g) method. In that method, draw your oval. Also on this class implement a KeyListener so that it listens for key events and on those events move the oval (JPanel) around on the other JPanel.

Do some testing and when you get stuck show us your code and we'll be glad to help you out. Hope that helps.
[ September 17, 2004: Message edited by: Gregg Bolinger ]
 
hugo egon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O.K. thank you you are realy nice. I'll test it and if it doesn't work you'll hear from me again.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!