• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

understanding JOptionPane

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic