import javax.swing.JOptionPane;
class ShowInput
{
    public static void main(String args[])
    {
        
        String s=(String)JOptionPane.showInputDialog(null, 
                  "Choose one", "Input",
              JOptionPane.INFORMATION_MESSAGE, null,
              "1,2,3", "2");        int n=Integer.parseInt(s);
        int nn=n*n;
        JOptionPane.showMessageDialog(
            null,
            s+"的平方为"+nn,
            "标题:平方",
            JOptionPane.PLAIN_MESSAGE);
            System.exit(0);
    }
}

解决方案 »

  1.   


    import javax.swing.JOptionPane;
    class ShowInput
    {
        public static void main(String args[])
        {
            
            String s=(String)JOptionPane.showInputDialog(null, 
                      "Choose one", "Input",
                  JOptionPane.INFORMATION_MESSAGE, null,
                  new Object[] {"1","2","3"}, "2");        int n=Integer.parseInt(s);
            int nn=n*n;
            JOptionPane.showMessageDialog(
                null,
                s+"的平方为"+nn,
                "标题:平方",
                JOptionPane.PLAIN_MESSAGE);
                System.exit(0);
        }
    }
      

  2.   

    new Object[] {"1","2","3"}为什么这里改动了下,就好了呢,不解中....
      

  3.   

    static Object showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) 
              提示用户在可以指定初始选择、可能选择及其他所有选项的模块化的对话框中输入内容。 
      

  4.   

    showInputDialog方法的参数要求是数组,传一个字符串当然不好用了。