I want to implement key listener on my puzzle game. i have done it with action listener but now want to move on with key listener.
My logic for action listener was that:
when a specific button is clicked it checks if is adjacent button's icon is null if it is null then their icons will be swapped Now, how can I do it with key listener? Thank you.
if( b1==e.getSource()){
if(b2.getIcon()==null){
b2.setIcon(b1.getIcon());
b1.setIcon(null);
}
else if(b5.getIcon()==null){
b5.setIcon(b1.getIcon());
b1.setIcon(null);
}
}
You tell us that you have implemented a KeyListener but it's not working. Without code, all we can do is guess, so here's mine:
Again for better and more specific help, then please tell us more of the details and show us your pertinent code, preferably as a minimal example program or MCVE.