• 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

Reading characters

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to read a single character using showInputDialog of JOptionPane???

Please help guys...
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kunagu varun wrote:How to read a single character using showInputDialog of JOptionPane???



Dialog Tutorial
 
kunagu varun
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The tutorial was extremely useful. Thanks a lot

But what i need actually is how to read only a single character from showInputDialog and store it in a variable of type char.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kunagu varun wrote:The tutorial was extremely useful. Thanks a lot

But what i need actually is how to read only a single character from showInputDialog and store it in a variable of type char.



You can get only Strings from a showInputDialog. You can then extract the first char of the String (after testing that it's not null and that its length is > 0) just as you would for any String charAt(0).

If this doesn't help and you're still running into problems, please show your code.
 
kunagu varun
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok thanks for the information provided. I will definitely try it out and inform you...
 
kunagu varun
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You very much pete stein...

This is the code that i have used after you have posted. It works 101% successfully

 
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kunagu varun wrote:It works 101% successfully


No it doesn't. Try either of the following and you'll see what I mean:
- press Cancel instead of OK
- press Enter without entering any text

That's why Pete said this:

pete stein wrote:(after testing that it's not null and that its length is > 0)

 
kunagu varun
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya right i just want to know whether it is possible to read characters form an input box...
 
Rob Spoor
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code is 100% correct - if the user enters what you expect him to enter. With just one or two simple checks your code will be perfect:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic