CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2008
    Posts
    49

    JOptionPane doesnt seem to be working...

    Code:
    		
    //Create JButton named "NewTree"
    JButton NewTree = new JButton("Create a new tree");
    
    	
    //Add action Listener
    NewTree.addActionListener (new ActionListener()
    {
         public void actionPerformed(ActionEvent e)
        {
    			 	
    			 	
              Object[] options = {"Strings", "Integers"};
    	
              int n = JOptionPane.showOptionDialog(null, "Which type of data will you be using in your tree?", "Data Type?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, options, options [2]);
    			 	
        }
    });
    Jcreator seems to think that the error seems to be on this this part of the code...

    Code:
    int n = JOptionPane.showOptionDialog
    the error message is...

    showOptionDialog(java.awt.Component,java.lang.Object,java.lang.String,int,int,javax.swing.Icon,java.lang.Object[],java.lang.Object) in javax.swing.JOptionPane cannot be applied to (<nulltype>,java.lang.String,java.lang.String,int,int,java.lang.Object[],java.lang.Object)

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: JOptionPane doesnt seem to be working...

    That is because after the two 'int' arguments you need to have an Icon object, or pass in 'null'. The other problem, once you get that to compile, is that you are accessing options[2]. Java arrays are 0 indexed. You have two options and they are accessed via: options[0] for the first one and options[1] for the second.

  3. #3
    Join Date
    Sep 2008
    Posts
    49

    Re: JOptionPane doesnt seem to be working...

    thanks for the help, that fixed it, im an idiot for not seeing that myself actually... sorry

  4. #4
    Join Date
    Feb 2008
    Posts
    966

    Re: JOptionPane doesnt seem to be working...

    No problem, when dealing with method calls that take a large amount of parameters, that happens quite often.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured