0

I have a grid of white squares and I need to know how to let a user click on one of the squares. Once the user clicks, the program checks what color the square is, if its black, its turns it white and vice-versa.

How can I do this?

Heres what the grid looks like

ninesalt
  • 4,054
  • 5
  • 35
  • 75
  • 1
    Implement a MouseListener and override its `mouseClicked` method. – TNT Jun 09 '14 at 20:24
  • 1
    You should make a `Square` class that knows its color. – BitNinja Jun 09 '14 at 20:25
  • TNT, whats the syntax for that? I cant find it anywhere. Could you please write a quick example using that? – ninesalt Jun 09 '14 at 20:51
  • And as a another [example](http://stackoverflow.com/questions/15421708/how-to-draw-grid-using-swing-class-java-and-detect-mouse-position-when-click-and/15422801#15422801) – MadProgrammer Jun 09 '14 at 21:20
  • *"whats the syntax for that? I cant find it anywhere."* - Not even in the two linked examples or all the mouse related questions on SO or [How to write mouse listeners](http://docs.oracle.com/javase/tutorial/uiswing/events/mouselistener.html)? I find that a little hard to believe – MadProgrammer Jun 09 '14 at 21:22

0 Answers0