Results 1 to 4 of 4
  1. #1
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default JOptionPane problem

    Hello fellow java programmers, I'm rokit boy, I was programming in C++ and I thought: "Why not try Java?". I know the basics of Java and I know how to write console applications and simple JFrame applications. I'm now using a more complex for for I/O programming so I used JOptionPane.
    Here is my code:
    Java Code:
    package org.tests.Test1;
    import javax.swing.*;
    
    public class Test {
    	
    	public static void main(String args[]) {
    		String password;
    		password = JOptionPane.showInputDialog(null, "Password: ","Admin Conrol",JOptionPane.PLAIN_MESSAGE);
    		if (password == "hi") {
    			JFrame myFrame = new JFrame();
    			String title;
    			title = "hi";
    			
    			myFrame.setTitle(title);
    			myFrame.setSize(300, 300);
    			myFrame.setVisible(true);
    		} if (password != "hi") {
    			JOptionPane.showMessageDialog(null, "Wrong Password", "ERROR", JOptionPane.ERROR_MESSAGE);
    		}
    	}
    	
    
    }
    I looked at it over and over and I can't find a mistake, but there is a mistake, when I type in "hi" in the input box it says "Wrong Password". Any help? I looked over it hundreds of times but still, I can't find whats wrong.

  2. #2
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: JOptionPane problem

    Anyone?

  3. #3
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    3

    Default Re: JOptionPane problem

    To compare between strings use the equals method or compareTo from the String class.
    You've compared references.

  4. #4
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: JOptionPane problem

    Thanks it worked :D
    Last edited by rokit boy; 02-05-2012 at 08:35 PM.

Similar Threads

  1. Problem with Array and Joptionpane
    By tkas in forum New To Java
    Replies: 3
    Last Post: 11-28-2011, 01:12 AM
  2. Problem with Array and Joptionpane
    By tkas in forum New To Java
    Replies: 4
    Last Post: 11-28-2011, 12:33 AM
  3. Problem with JOptionPane
    By chrisLU5 in forum New To Java
    Replies: 8
    Last Post: 05-05-2011, 10:04 PM
  4. Problem JOptionPane try catch
    By jason99 in forum New To Java
    Replies: 1
    Last Post: 07-10-2009, 10:39 PM
  5. JOptionPane problem
    By MomenT in forum New To Java
    Replies: 22
    Last Post: 10-02-2008, 05:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •