Here you can find the source of getNumber(JTextField field, Integer defaultInt)
public static int getNumber(JTextField field, Integer defaultInt)
//package com.java2s; //License from project: Open Source License import javax.swing.JTextField; public class Main { public static int getNumber(JTextField field, Integer defaultInt) { String value = field.getText(); Integer valueInt = null;//w w w.j a v a 2 s .com if (value.equals("")) { valueInt = defaultInt; } else { try { valueInt = Integer.parseInt(value); } catch (Exception e) { return defaultInt; } } return valueInt; } }