Hi guys, I have got an Array of JButtons, that are in a gridLayout 7,7.
I have added an actionListener to these buttons that at the moment only prints out "Button clicked"
At the moment some of these JButtons have an ImageIcon on them and some of them are blank.
For example if I have three JButtons in positions:
[3,3] [3,4] [3,5]
[] [X] [X]
The first is blank and the rest have a ImageIcon.
What I want to happen is when a user clicks on a button with an ImageIcon ([3,5]) and then clicks on a button that is blank ([3,3]) the JButton will affectivly jump over the middle button and will then be at position [3,3] :
[3,3] [3,4] [3,5]
[x] [] []
I know I can do this by making the button have an ImageIcon and make the others blank to have the affect it is being 'jumped over'.
What I want to know is how can I check the position of the JButton the user has click and if it is in a line with the other Jbutton?
To make it clear if a user clicks JButton [3,5] and then wanted to 'jump' it to [0,1], I need a test to show this is not allowed. The JButton is only allowed to move twice to the left, right, up or down depending if the immediate button is 'full' and the button after is 'blank'.
I really hope this makes sense.
1. Would I write code to check what the position in the array of the JButton that the user has clicked is.
2. Then check the second position of the second button user has clicked //How would I check if the user clicked to the left,right,up or down?
Thanks