Here you can find the source of promptForFloat(Component parentComponent, String message, String title, float oldValue)
Parameter | Description |
---|---|
message | the prompt message |
title | the dialog title |
oldValue | the original float value |
static public float promptForFloat(Component parentComponent, String message, String title, float oldValue)
//package com.java2s; //License from project: Open Source License import java.awt.Component; import javax.swing.JOptionPane; public class Main { /**/*from w w w. j ava2 s.c o m*/ * Utility function to prompt for new float value * * @param message the prompt message * @param title the dialog title * @param oldValue the original float value * @return the new float value */ static public float promptForFloat(Component parentComponent, String message, String title, float oldValue) { float result = oldValue; String newValue = promptForString(parentComponent, message, title, Float.toString(oldValue)); if (newValue != null) { try { result = Float.parseFloat(newValue); } catch (NumberFormatException e) { result = oldValue; } } return result; } /** * Utility function to prompt for new string value * * @param message the prompt message * @param title the dialog title * @param oldValue the original string value * @return the new string value */ static public String promptForString(Component parentComponent, String message, String title, String oldValue) { String result = oldValue; String newValue = (String) JOptionPane.showInputDialog(parentComponent, message, title, JOptionPane.PLAIN_MESSAGE, null, null, oldValue); if (newValue != null) { result = newValue; } return result; } }