Results 1 to 2 of 2
  1. #1
    romina is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default Help with text fields in Java

    I am trying to sut this game up so that if the text "NateTheWizard" are typed in a text field, then the 'new game' button will load level 3 instead of level one.

    With this text, no matter what is in the field, it loads level one:

    Java Code:
    public void startButton_actionPerformed(ActionEvent e) {
    if((password.getText() == "NateTheWizard")){
    DotStealthFrame.contentPane.removeAll();
    DotStealthFrame.contentPane.add(new Level3(), BorderLayout.CENTER);
    DotStealthFrame.contentPane.updateUI();
    DotStealthFrame.contentPane.getComponent(0).requestFocusInWindow();
    
    lvl3Popup level3Pop = new lvl3Popup();
    level3Pop.setModal(false);
    level3Pop.setLocation(300, 300);
    level3Pop.setVisible(true);
    }
    
    else{
    DotStealthFrame.contentPane.removeAll();
    DotStealthFrame.contentPane.add(new Level1(), BorderLayout.CENTER);
    DotStealthFrame.contentPane.updateUI();
    DotStealthFrame.contentPane.getComponent(0).requestFocusInWindow();
    
    lvl1Popup level1Pop = new lvl1Popup();
    level1Pop.setModal(false);
    level1Pop.setLocation(300, 300);
    level1Pop.setVisible(true);
    };
    }

  2. #2
    trill is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    I'm rusty on my Java, and I'm not at a computer in which I can test this.

    However, I believe if you want to compare two strings in Java you need to use the .equals method rather than ==.
    example
    Java Code:
    if(password.getText().equals("NateTheWizard")){
    }
    Greetings.

Similar Threads

  1. Jsp / Java cannot get fields
    By Dracos in forum New To Java
    Replies: 0
    Last Post: 02-04-2008, 09:39 PM
  2. Show Text Fields on combo Box selected value
    By smajidali26 in forum AWT / Swing
    Replies: 0
    Last Post: 11-29-2007, 09:28 AM
  3. Top menu fields hiding
    By youayshu in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-13-2007, 07:10 AM
  4. How To Add Fields And Generating Getter-Setters
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-30-2007, 11:13 PM
  5. Special characters in text fields
    By Felissa in forum Web Frameworks
    Replies: 0
    Last Post: 06-27-2007, 04:47 PM

Posting Permissions

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