J
jim.hunt533
New to Java, I'm looking for a general way to set up a game board as a
grid of cells and communicate with them. So far I have defined a new
class, Cell, which extends JTextField and has some extra fields like
rowNo and columnNo, then populated a JPanel with a GridLayout(3,3)
with nine instances of Cell(i,j).
The problem then is how to code an event handler (like
KeyTyped(KeyEvent e)) in the Class to know which instance of Cell has
received the event.
The closest I have got so far finding ActionCommand and defining that
to be a row+column id string for the instance as it is constructed.
This is then visible in a System.out.println of the Event but I have
not found a way to extract it. I'm sure that is an abuse of
ActionCommand anyway.
Any and all ideas on better/correct techniques will be most welcome.
grid of cells and communicate with them. So far I have defined a new
class, Cell, which extends JTextField and has some extra fields like
rowNo and columnNo, then populated a JPanel with a GridLayout(3,3)
with nine instances of Cell(i,j).
The problem then is how to code an event handler (like
KeyTyped(KeyEvent e)) in the Class to know which instance of Cell has
received the event.
The closest I have got so far finding ActionCommand and defining that
to be a row+column id string for the instance as it is constructed.
This is then visible in a System.out.println of the Event but I have
not found a way to extract it. I'm sure that is an abuse of
ActionCommand anyway.
Any and all ideas on better/correct techniques will be most welcome.