/* 3magic Coffee Table Tutorial 13 ValidatorGrid.java - Custom Validation. © 1997-1999 3magic. All rights reserved worldwide. */ import java.awt.*; import java.lang.*; import CoffeeTable.Grid.*; /** * Here's an extension to GridPanel to do custom validation. */ public class ValidatorGrid extends GridPanel { TextArea fMsg; // Constructor public ValidatorGrid() { super(); } // Constructor public ValidatorGrid(int numRows, int numCols, TextArea aMsg) { super(numRows, numCols); fMsg = aMsg; } // Override validate to do custom validation of cell inputs. public boolean validate(String aText, Point editCell) { boolean valid = true; if ((aText != null) && !aText.equals("")) { fMsg.appendText("Data Entry = '" + aText + "'\n"); try { int x = Integer.parseInt(aText); fMsg.appendText("Number OK = '" + x + "'\n"); } catch (Exception e) { fMsg.appendText("Not a Number! Please enter a Number!\n"); TextField field = this.getEditTextField(); if (field != null) { field.selectAll(); field.requestFocus(); } valid = false; } } return valid; } }