如何使用JOptionPane仅输出数组的一部分?

时间:2016-10-23 06:04:56

标签: java arrays swing joptionpane

我很难将部分数组输出到JOptionPane.showOptionDialog()。我有一个用户提示要求1-10之间的整数,并希望从数组输出该数量的项目。

options = JOptionPane.showInputDialog("How many options would you like?"+
                        "\n\nPlease note that you must input a number between 1-10");

try{
    numberofoptions = Integer.parseInt(options);
}
catch(NumberFormatException e){
    JOptionPane.showMessageDialog(null, "Remember to only input a numerical integer");
}

JOptionPane.showOptionDialog(null, "Please select a restaurant.", "Restaurant Selector",
    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Restaurants, Restaurants[0]);

exit = JOptionPane.showConfirmDialog(null, "Do you wish to continue?", "Restaurant Selector", 
        JOptionPane.YES_NO_OPTION);

1 个答案:

答案 0 :(得分:0)

您可以使用datatype方法获取第一个Arrays.copyOf餐馆:

n