how can i use KeyEvent to replace JTextField.getSource in this part so that when an input is typed, there's no need for pushing "Enter"
public void actionPerformed(ActionEvent e) {
int rowSelected = -1;
int colSelected = -1;
JTextField source = (JTextField) e.getSource();
boolean found = false;
for (int row = 0; row < GRID_SIZE && !found; ++row) {
for (int col = 0; col < GRID_SIZE && !found; ++col) {
if (tfCells[row][col] == source) {
rowSelected = row;
colSelected = col;
found = true;
}
}
}
int answer = Integer.parseInt(tfCells[rowSelected][colSelected].getText());
if (answer == puzzle[rowSelected][colSelected]) {
tfCells[rowSelected][colSelected].setBackground(getColor(puzzle[rowSelected][colSelected]));
count--;
} else {
tfCells[rowSelected][colSelected].setBackground(Color.RED);
}