Here you can find the source of getIntegerFromTextField(JTextField tf, int previousValue)
Parameter | Description |
---|---|
tf | the tf |
previousValue | the previous value |
public static int getIntegerFromTextField(JTextField tf, int previousValue)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import javax.swing.JTextField; public class Main { /**/*from ww w . j ava 2 s .c o m*/ * Gets the integer from text field. * * @param tf * the tf * @param previousValue * the previous value * @return the integer from text field */ public static int getIntegerFromTextField(JTextField tf, int previousValue) { if (tf.getText().length() > 0) { try { int num = Integer.parseInt(tf.getText()); tf.setForeground(Color.black); return num; } catch (NumberFormatException ex) { tf.setForeground(Color.red); } } return previousValue; } }