• 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

Comparing Strings

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to get some input using JOptionPane. I want the user to enter a string and if this string is equal to the string I'm looking for I want to execute some code.
The problem is I'm unsure how to do this. I've tried the following.



 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"mesmer surprise", please check your private messages for an important administrative matter.
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't it work for you?

If not can you post two sample strings that you are using?
 
Greenhorn
Posts: 21
Eclipse IDE Firefox Browser Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friend !!. Its simple

Use showInputDialog() in JOptionPane to get String

showInputDialog() has different method signatures other than i have used. please see javadoc .

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

Senthil Kumar wrote:


I'd change that to
, or at least

JOptionPane.showInputDialog returns null if the user presses Cancel, so your code would throw a NullPointerException if that woud occur.
 
Senthil Kumar
Greenhorn
Posts: 21
Eclipse IDE Firefox Browser Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friend , I am not giving you the Exact Code.

I gave you an Example. you have to write events for that.

Please have a look on this

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JOptionPane.html


http://faq.javaranch.com/java/NotACodeMill

 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know, but my warning is to prevent any unexpected errors when Michael just copies your little example and is not aware of the possible NullPointerException.
 
Senthil Kumar
Greenhorn
Posts: 21
Eclipse IDE Firefox Browser Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:I know, but my warning is to prevent any unexpected errors when Michael just copies your little example and is not aware of the possible NullPointerException.



Okay Rob
reply
    Bookmark Topic Watch Topic
  • New Topic