java - Simple Key Listeners -


alright, i'm making simple pong game first real java project. "racquet" on bottom of jframe works , all, except motion part. need able read input keyboard. know can done through keylistener (i think) method; , java documentation website tells me can bind keys actions. way efficient/easiest; , if so, what's simplest way implement it? realize isn't simple

if(keypressed == vk_left)      

but i've been having terrible time trying figure these dang things out. please?

key bindings preferred method , tend less trouble some

inputmap im = getinputmap(); actionmap = getactionmap();  im.put(keystroke.getkeystroke(keyevent.vk_left, keyevent.ctrl_down_mask), "left"); im.put(keystroke.getkeystroke(keyevent.vk_right, keyevent.ctrl_down_mask), "right");  am.put("left", new abstractaction() {     @override     public void actionperformed(actionevent e) {         // code go left     } }); am.put("right", new abstractaction() {     @override     public void actionperformed(actionevent e) {         // code right     } }); 

what's cool if create actions separate classes, use same actions on jbuttons!


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -