Here you can find the source of getDoubleFromTextField(JTextField textField, double defaultValue)
public static double getDoubleFromTextField(JTextField textField, double defaultValue)
//package com.java2s; /*/* w w w . j av a2s. com*/ * Utils.java * * Copyright (c) 2009 JAM Development Team * * This package is distributed under the Lesser Gnu Public Licence (LGPL) * */ import javax.swing.*; public class Main { /** * @return the value in a text field as a double. * If the text field contents do not represent a valid double then the * default value is inserted into the text field and returned. */ public static double getDoubleFromTextField(JTextField textField, double defaultValue) { double value = defaultValue; try { value = Double.parseDouble(textField.getText()); } catch (NumberFormatException nfe) { textField.setText(defaultValue + ""); } return value; } }