Here you can find the source of chooseIndex(String message, String messageTitle, Object[] objects, Object initialObject)
Parameter | Description |
---|---|
message | a parameter |
messageTitle | a parameter |
objects | a parameter |
initialObject | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static int chooseIndex(String message, String messageTitle, Object[] objects, Object initialObject) throws Exception
//package com.java2s; /*// w w w . j a va2s. c om * Copyright (C) 2010-2014 Andreas Maier * CONRAD is developed as an Open Source project under the GNU General Public License (GPL). */ import javax.swing.JOptionPane; public class Main { /** * Asks the User to select an Object from a given array of Objects. * The index of the selected object is returned. * @param message * @param messageTitle * @param objects * @param initialObject * @return the index of the chosen object * @throws Exception */ public static int chooseIndex(String message, String messageTitle, Object[] objects, Object initialObject) throws Exception { Object input = JOptionPane.showInputDialog(null, message, messageTitle, JOptionPane.INFORMATION_MESSAGE, null, objects, initialObject); if (input == null) throw new Exception("Selection aborted"); int index = -1; for (int i = 0; i < objects.length; i++) { if (objects[i].equals(input)) index = i; } return index; } }