Here you can find the source of getNum(JTextField txt, double defaultNum)
public static double getNum(JTextField txt, double defaultNum)
//package com.java2s; //License from project: Academic Free License import javax.swing.JTextField; public class Main { public static double getNum(JTextField txt) { return getNum(txt, 0); }//from ww w . jav a2 s . c om public static double getNum(JTextField txt, double defaultNum) { double num = defaultNum; try { String str = txt.getText().trim(); num = Double.parseDouble(str); } catch (Exception ex) { //ex.printStackTrace(); } return num; } }