• Post Reply Bookmark Topic Watch Topic
  • New Topic

understanding JOptionPane  RSS feed

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm aware JOptionPane isnt the most suitable for getting user's input

anyway, i came to this:

from API, i used:
public static String showInputDialog(Object message)
throws HeadlessExceptionShows a question-message dialog requesting input from the user. The dialog uses the default frame, which usually means it is centered on the screen.

@param is an Object and i pass a String, which is an obj, yes, but...
Parameters:
message - the Object to display

dont quite well get it ...


why is that cast needed for?
[ June 08, 2005: Message edited by: miguel lisboa ]
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miguel,
Using JDK 1.4.2_07 on Windows XP, the cast is not needed. Here is a sample program to demonstrate:

When you run the above code, a window containing a text field and a button, will be displayed. When you click on the button, a "JOptionPane" will be displayed. When you close the "JOptionPane", the text you entered into the "JOptionPane" will be displayed in the application window's text field.

Good Luck,
Avi.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, Avi

i understood your code; what waspuzzling me was the fact all the code i saw had that cast and coudnt understand why

actually i'm running winXp with tiger

still, i dont get that param being an Object to display the message...
[ June 08, 2005: Message edited by: miguel lisboa ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything in java is an Object. Technically as long as the object has a toString() method, you could use that as the parameter.

As far as the following statement is concerned:

Using JDK 1.4.2_07 on Windows XP, the cast is not needed

I'm not sure what Windows XP has to do with the fact that the cast is not needed. The cast is simply not needed. It doesn't care about the OS.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, Gregg
Technically as long as the object has a toString() method, you could use that as the parameter.

and as all objects inherit from Object and this one has a toString() method, all is well

but what wasnt clear is that, if programmer usually wanna display some message (a written one, i mean) that could be clearer - but i get it: someoneelse might want to use some other way out...

as to winXP that was silly of me
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!