This site requires JavaScript, please enable it in your browser!
Greenfoot back
TheKidChameleon
TheKidChameleon wrote ...

2012/12/4

KeyAdapter

TheKidChameleon TheKidChameleon

2012/12/4

#
Is there a trick to accessing the java KeyAdapter class in Greenfoot? I'm not sure if it's an import statement I'm not getting right or if there's something else I need to know.
danpost danpost

2012/12/5

#
It appears you need a component to add the listener to. You will need to import 'java.awt.Component', 'java.awt.event.KeyListener', and 'java.awt.event.KeyAdapter'. I believe you create a sub-class of KeyAdapter and write your methods for the key events you are looking for in it. Then create a new KeyAdapter object (using your sub-class name) and use the 'addKeyListener' method to apply it to a Component object.
You need to login to post a reply.