Java JOptionPane Message promptForFloat(Component parentComponent, String message, String title, float oldValue)

Here you can find the source of promptForFloat(Component parentComponent, String message, String title, float oldValue)

Description

Utility function to prompt for new float value

License

Open Source License

Parameter

Parameter Description
message the prompt message
title the dialog title
oldValue the original float value

Return

the new float value

Declaration

static public float promptForFloat(Component parentComponent, String message, String title, float oldValue) 

Method Source Code

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

Related

  1. pause(final String msg)
  2. plain(String title, Object message, JComponent parent)
  3. popup(Component parent, String message, String title)
  4. popupMessage(String message)
  5. popupMessage(String title, String message)
  6. promptForString(Component parentComponent, String message, String title, String oldValue)
  7. queryBoolean(String message)
  8. queryDouble(String message, double initialValue)
  9. queryInt(String message, int initialValue)