Java tutorial
//package com.java2s; import javax.swing.JTextField; public class Main { public static Integer getInteger(JTextField txt, Integer defaultVal) { String str = txt.getText(); if (str.trim().length() <= 0) return defaultVal; int val = 0; try { val = Integer.parseInt(str); } catch (NumberFormatException ex) { } return new Integer(val); } }