File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Comparing Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparing Strings" Watch "Comparing Strings" New topic
Author

Comparing Strings

Michael Crump
Greenhorn

Joined: Jan 26, 2009
Posts: 1
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.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

"mesmer surprise", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
Doesn't it work for you?

If not can you post two sample strings that you are using?
Senthil Kumar
Greenhorn

Joined: Jul 17, 2007
Posts: 21
Hi Friend !!. Its simple

Use showInputDialog() in JOptionPane to get String

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



Preparing for SCJP 1.6
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Senthil Kumar
Greenhorn

Joined: Jul 17, 2007
Posts: 21
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

Joined: Oct 27, 2005
Posts: 19541
    
  16

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

Joined: Jul 17, 2007
Posts: 21
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing Strings
 
Similar Threads
escape character nightmare - please help
How to replace string in a file
re-write help needed
renaming object and creating object in run time
StringBuffer problem