Here you can find the source of validarNumeroInteiro(KeyEvent evt)
public static void validarNumeroInteiro(KeyEvent evt)
//package com.java2s; //License from project: Open Source License import java.awt.event.KeyEvent; import javax.swing.JTextField; public class Main { public static void validarNumeroInteiro(KeyEvent evt) { if (!Character.isDigit(evt.getKeyChar()) && evt.getKeyChar() != '-') evt.consume();//from w w w . java 2 s .c o m if (((JTextField) evt.getSource()).getText().length() > 0 && evt.getKeyChar() == '-') evt.consume(); } }