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);
}
}