Here you can find the source of newIntegerValue(JTextField text, int oldValue)
Parameter | Description |
---|---|
text | a parameter |
oldValue | a parameter |
public static int newIntegerValue(JTextField text, int oldValue)
//package com.java2s; /**/* w w w . j a v a 2 s. co m*/ * Copyright (C) 2018 Lars Dam * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 3.0 * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * See: http://www.gnu.org/licenses/gpl-3.0.html * * Problemen in deze code: * - ... * - ... */ import javax.swing.JTextField; public class Main { /** * Bepaal de nieuwe integer waarde voor een textfield Als het tekstveld een * geldig getal bevat, wordt deze waarde geretourneerd anders de oude waarde * * @param text * @param oldValue * @return */ public static int newIntegerValue(JTextField text, int oldValue) { int value; try { value = Integer.parseInt(text.getText()); } catch (Exception e) { value = oldValue; } text.setText(Integer.toString(value)); return value; } }