int (JTextField field, int minValue, int defValue) { if (field instanceof IntegerField) { return ((IntegerField)field).getValue(); } else { try { return Math.max(Integer.parseInt(field.getText()), minValue); } catch (NumberFormatException e) { return defValue; } } }