aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Reading characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Reading characters" Watch "Reading characters" New topic
Author

Reading characters

kunagu varun
Ranch Hand

Joined: Apr 13, 2010
Posts: 38
How to read a single character using showInputDialog of JOptionPane???

Please help guys...
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
kunagu varun wrote:How to read a single character using showInputDialog of JOptionPane???


Dialog Tutorial
kunagu varun
Ranch Hand

Joined: Apr 13, 2010
Posts: 38
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Apr 13, 2010
Posts: 38
ok thanks for the information provided. I will definitely try it out and inform you...
kunagu varun
Ranch Hand

Joined: Apr 13, 2010
Posts: 38
Thank You very much pete stein...

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

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

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)


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
kunagu varun
Ranch Hand

Joined: Apr 13, 2010
Posts: 38
ya right i just want to know whether it is possible to read characters form an input box...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading characters