Java JTextField Number getNumber(JTextField field, Integer defaultInt)

Here you can find the source of getNumber(JTextField field, Integer defaultInt)

Description

get Number

License

Open Source License

Declaration

public static int getNumber(JTextField field, Integer defaultInt) 

Method Source Code

//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;
    }
}

Related

  1. format(JTextField txt, double num, String fmt)
  2. getNum(JTextField txt, double defaultNum)
  3. largeEqualThan(javax.swing.JTextField input, double x)
  4. parseIntFromField(JTextField jField, int pDefault)
  5. placeDoubleTextInField(JTextField inField, int length, double toPlace)
  6. readDoubleFromField(JTextField inField, double defaultValue)