Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to activate key repeating with action listener  RSS feed

 
joh wra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am working on a 3D-Projekt, but that's not the point.
I wanted to call a function to turn the camera and want, that the function ist called while the key is pressed.

I tried following:



I think, I have to change the ActionListener "onAction", but I can't remember in which way.
In the actual code the programm only once perform the action when the key is pressed.

I already tried
while(pressed) {setViewAngle(-1)}
but that didn't work, but get the whole programm to halt.

So I thought of key repeating. Maybe you know how to do this?
 
Tony Docherty
Bartender
Posts: 3264
81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java's ActionListener interface doesn't have an onAction() method it has an actionPerformed() method.

When you say "key pressed" do you mean a keyboard key or do you mean a mouse holding a gui button pressed or do you mean something else altogether?
 
joh wra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean a keyboard input. I don't want to use the GUI for this.
 
Tony Docherty
Bartender
Posts: 3264
81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please confirm the type of application this is, is it command line, Swing based or something else.
 
joh wra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a jmonkeyengine projekt. That means it is a window in a 3D-Environment, called SimpleApplication. There is also an Overlay GUI in it and a run Method. Maybe I have to use this?
 
Tony Docherty
Bartender
Posts: 3264
81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with this setup but you would probably need to register a type of Key Listener to listen for keyboard events and hopefully it will provide a method which is notified repeatedly whilst a key is held down.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!