I am going to use two variables, both of the data type JButton: one is called selectedSquare, the other called newSqaure. How would I use the variables to pint out the location of the selected sqaure and where the icon should go if the new square is then selected?
When you click on a button the listener is called with an event object. In the listener you should add code as has been discussed earlier in the thread. These last discussions were about how to save and work with a "selected" square. First click saves it, later clicks test and use it as a source or clear it if was the same square.
All that I have changed is adding the variables selectedSqaure and newSquare at the beginning. I have no idea what to change out of a fear of not being able to change it back. I have yet to think like a programmer on what to do next. I do as I think, not think then do
I think I may be in one. Do you have any suggestions? I don't have the time to scrap this code and start from the drawing board. I have already told my lab partner that if we don't figure out how to do the AI by Monday, then we would simply make it a two player game.
We have been talking about the first step in the list: selecting a square and remembering it
Most of the possibilities have been discussed several times. Make a list of the steps the code will have to do to do the selection. Get that done first. That will be the guide you'll use to write the code.
The only code to scrap is what is currently in the listener. It needs to be redesigned.
I have but nothing is working. I keep thinking I have something, but it doesn't compile. I work better after seeing a good example, and I have tried looking at other types of code, but they work by clicking and dragging a piece, or the code just doesn't make sense to me. I am using an icon as the piece, and I would just like to see an example of when you click on a square, and then click on another square, the icon will move.
First get rid of the for loops. That code is not being used.
The selectedSqr should be the value of the source of the event when a button/square is clicked.
On The first click you save it, on the second click you use it as the source of the move. You detect the first click by seeing that selectedSqr is null. It won't be null for the second click.
This is what I mean. I have spent most of my life working by example, but because I don't have a good example to go off of, I don't know what I am supposed to do. BTW, this is just the coding for the ButtonHandler class, not the whole class.
The second if statement was supposed to set the information in the selected square to a temporary section, which would transfer the status of the selected square to the new square, which would set the icon in the new square, and delete the icon in the old square.