import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.beans.*; public class TicTacTF extends JTextField { private int rowlocation; private int collocation; private Board b; //create a reference to the result tf //take as input a reference to the result textfield public TicTacTF(int rowlocation, int collocation, Board b) { super(""); this.rowlocation = rowlocation; this.collocation = collocation; this.addActionListener(new TFListener(this)); //set my reference to the result tf = input ref this.b = b; this.setColumns(1); } class TFListener implements ActionListener { private TicTacTF parent = null; public TFListener(TicTacTF parent) { super(); this.parent = parent; } public void actionPerformed(ActionEvent evt) { String s = parent.getText(); if(s.length() != 1) { //set text of result tf to be "ERROR:..." System.out.println("ERROR"); } else { b.placeChar(s.charAt(0), rowlocation, collocation); } } } }