This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Very basic question about J.OptionPane.showMessageDialog method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Very basic question about J.OptionPane.showMessageDialog method" Watch "Very basic question about J.OptionPane.showMessageDialog method" New topic
Author

Very basic question about J.OptionPane.showMessageDialog method

Karen Haq
Greenhorn

Joined: Mar 17, 2010
Posts: 22
Hi,
I'm trying to understand how to read (i.e., how to translate from geek speak to English) the overwhelming and detailed Java API as I'm learning how to code. Regarding this method I copied from the API:

static String showInputDialog(Object message)
Shows a question-message dialog requesting input from the user.


In "English", this method is a class static method that returns a String type and the method's argument is the class's field message? So how does "Object" come into play here? I understand Object is the root class (of all classes) but I don't understand its relationship to "message" because isn't message a field for J.OptionPane class?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

The message is of type object because it doesn't have to be a String. You can pass a String[] which will be shown as all Strings below each other, and even complete Components like JTextField, JButton, JPanel, etc.

Although the actual supported Object types are not clearly documented, a little investigation showed that the following are allowed:
- Component: the component will be added
- Icon: a text-less label with the icon will be added
- Object[]: all elements of the array are added using the same code, so the Object[] can contain Component, Icon, Object[], etc
- anything else will be converted into a String which is added as a label


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Karen Haq
Greenhorn

Joined: Mar 17, 2010
Posts: 22
Okay, I think I got.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Very basic question about J.OptionPane.showMessageDialog method
 
Similar Threads
Using the Class class
What is the best way to transmit the find criteria from View to Model and to Business
Confused about Static lifetime
System.in,System.out,System.err
Can I pass JTextField as parameter?