Here you can find the source of askForAStringInArrayReturning(String question, String header, T[] options, String errorMessage, String errorHeader)
Parameter | Description |
---|---|
question | the question to ask |
header | the header of the box |
options | the options the user can chose from |
errorMessage | the error message when something is wrong |
errorHeader | the error message header box when something is wrong |
T | the type in the array |
public static <T> T askForAStringInArrayReturning(String question, String header, T[] options, String errorMessage, String errorHeader)
//package com.java2s; //License from project: Open Source License import javax.swing.*; public class Main { /**/*from ww w . j av a 2 s.c o m*/ * Ask in a swing gui for something in array * @param question the question to ask * @param header the header of the box * @param options the options the user can chose from * @param errorMessage the error message when something is wrong * @param errorHeader the error message header box when something is wrong * @param <T> the type in the array * @return the value found */ public static <T> T askForAStringInArrayReturning(String question, String header, T[] options, String errorMessage, String errorHeader) { return options[askForAStringInArray(question, header, options, errorMessage, errorHeader)]; } /** * Ask in a swing gui for something in array * @param question the question to ask * @param header the header of the box * @param options the options the user can chose from * @param <T> the type in the array * @return the value found */ @SafeVarargs public static <T> T askForAStringInArrayReturning(String question, String header, T... options) { return options[askForAStringInArray(question, header, options, "Vous devez faire un choix", "Erreur choix")]; } /** * Ask in a swing gui for something in array * @param question the question to ask * @param header the header of the box * @param options the options the user can chose from * @param errorMessage the error message when something is wrong * @param errorHeader the error message header box when something is wrong * @return the value found */ public static int askForAStringInArray(String question, String header, Object[] options, String errorMessage, String errorHeader) { int res = JOptionPane.CLOSED_OPTION; while (res == JOptionPane.CLOSED_OPTION) { res = JOptionPane.showOptionDialog(null, question, header, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, //do not use a custom Icon options, //the titles of buttons options[0]); //default button title if (res == JOptionPane.CLOSED_OPTION) { JOptionPane.showMessageDialog(null, errorMessage, errorHeader, JOptionPane.ERROR_MESSAGE); } } return res; } }