Results 1 to 2 of 2
  1. #1
    braskez is offline Member
    Join Date
    Oct 2012
    Posts
    14
    Rep Power
    0

    Default Doesn't recognize string value?

    Alright, so I was trying to code a simple command system but I ran into a problem along the way. I tried to do the code below. But even when commandBar was equal to exit it would print: Command Value: "exit". So I am not sure what I am doing wrong. Any help is appreciated. Thanks!

    Java Code:
    public void actionPerformed(ActionEvent e) {
        	System.out.println("actionPerformed: " + e.getSource().toString());
            if(e.getSource() == commandEnter){
            	String command = commandBar.getText();
            		if(command == "exit"){
            			dispose();
            			System.exit(0);
            		}else{
            			System.out.println("Command not recognized");
                    	System.out.println("Command Value: \""+command+"\"\n");
    
            		}
            }else if(e.getSource() == exit){
    			dispose();
    			System.exit(0);
            }
    }

  2. #2
    braskez is offline Member
    Join Date
    Oct 2012
    Posts
    14
    Rep Power
    0

    Default Re: Doesn't recognize string value?

    Nevermind. I fixed it by doing the following for line 5:

    Java Code:
            		if(command.equals("exit")){
    Thanks anyways.

Similar Threads

  1. String replaceAll doesn't work!!!
    By danoc93 in forum New To Java
    Replies: 3
    Last Post: 06-25-2012, 11:29 AM
  2. Nimbus LaF doesn't recognize javax.swing.JTable?
    By rudeboy in forum AWT / Swing
    Replies: 10
    Last Post: 12-04-2011, 08:14 PM
  3. string prompt doesn't appear in showInputDialog
    By saxophone in forum New To Java
    Replies: 4
    Last Post: 04-01-2010, 10:05 PM
  4. String array for Choice, JOptionPane doesn't show
    By themburu in forum Java Applets
    Replies: 5
    Last Post: 05-29-2008, 01:10 PM
  5. (newbie) String doesn't compile?!
    By jon80 in forum New To Java
    Replies: 5
    Last Post: 04-09-2008, 08:37 AM

Posting Permissions

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