views:

167

answers:

3

I'm learning Java and I have no idea how to do this.

I dragged a button on the form in Netbeans, double clicked it and it created this event:

@Action
public void HelloClickMethod() 
{
    JOptionPane.showMessageDialog(this, "The message!", "This is supposed to be the MessageBox title."); 
}

This is the exception the IDE brings up.

Cannot find symbol. Symbol: showMessageDialog()

Edit 1> Now I changed it to this:

@Action
public void HelloClickMethod()
{
    JOptionPane.showMessageDialog(this, "The message!", "This is supposed to be the MessageBox title.",JOptionPane.ERROR_MESSAGE);
}

However the IDE is saying I have an error in the word 'this'. "Cannot find symbol". I don't understand. Why is it so dificult and why are the errors so esoteric. :P

A: 

The showMessageDialog method does not take 3 parameters. Try this:

  JOptionPane.showMessageDialog(this, "The message!", "This is supposed to be the MessageBox title.", JOptionPane.ERROR_MESSAGE);

There are 3 methods named showMessageDialog, one with 2 parameters (component and message), 4 parameters (component, message, title, message type) and 5 parameters (component, message, title, message type, icon).

Vincent Ramdhanie
I don't have javac in this computer but I am almost certain that it can take 3 arguments.http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
Anzurio
Please read the edit.
Sergio Tapia
I am looking at the API docs http://java.sun.com/javase/7/docs/api/javax/swing/JOptionPane.html and there are only 3 methods? I see the tutorial that shows code with 3 parameters but...I have to check.
Vincent Ramdhanie
OK. I checked. I have javase6 installed and it does not allow the 3 parameter version given in the tutorial.
Vincent Ramdhanie
+2  A: 

I can think of the following cause: you might not be "importing" the package containing JOptionPane. Try:

 import javax.swing.*;

On top of your source file. Or, use

javax.swing.JOptionPane.showMessageDialog(this, "The message!", "This is supposed to be the MessageBox title.", JOptionPane.ERROR_MESSAGE);

After questioner edit:

Other cause is the location of the method, if you are in an static context, you can't use this.

Anzurio
Looking back at the retardedness of my question is very humbling. Tip! Never look at code/questions you've written in the past, you'll only blush. Hahahaha.
Sergio Tapia
A: 

I've been creating a message box using the jOptionPane, all i want is to remove the jOptionPane on the form when i run the application. how would i do that?

jOPtionPane1.showMessageBox(frame, "My message","My title",null);

i am using netbeans 6.9, can you help me to hide the jOptionPane when the application run..

and since were in the messageBox, can you show some code for the showDialogBox,showinputBox

thanks..

here's my email

[email protected]

Jess Rubio