|
-
March 4th, 2009, 10:31 AM
#1
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)
-
March 4th, 2009, 10:49 AM
#2
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.
-
March 4th, 2009, 01:06 PM
#3
Re: JOptionPane doesnt seem to be working...
thanks for the help, that fixed it, im an idiot for not seeing that myself actually... sorry
-
March 4th, 2009, 01:23 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|