java - Program Cannot Discern What The String Is -



java - Program Cannot Discern What The String Is -

this question has reply here:

how compare strings in java? 23 answers

i trying create game unscramble words. cannot seem check if user's guess equal actual answer. seems no matter have actual word not equal users guess, while here. is there other way pause code , wait users input other having while loop?

import javax.swing.joptionpane; public class loop extends createwindow{ private static final long serialversionuid = 1l; public static boolean running = true; public static void gamestart(){ if(running){ int wordnum = 0; (int i=0;i<=9;i++){ field.settext(""); setscrambledword(i); while(enter == false){ system.out.println(useranswer); system.out.println(enter); system.out.println(score); } useranswer = area.gettext(); if(useranswer == normalwords[wordnum]){ joptionpane.showmessagedialog(null, "legos", useranswer, joptionpane.ok_option); }else if(useranswer != normalwords[wordnum]){ joptionpane.showmessagedialog(null, "sogel", useranswer, joptionpane.ok_option); } area.settext(""); come in = false; wordnum++; } } } public static void main(string[] args){ new createwindow(); running = true; gamestart(); } } import java.awt.borderlayout; import java.awt.graphics; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.jtextarea; import javax.swing.jtextfield; public class createwindow extends jframe { private static final long serialversionuid = 1l; jpanel panel = new jpanel(); public static int score = 0; static jtextarea area = new jtextarea(10,40); static jtextfield field = new jtextfield(40); jbutton button = new jbutton("press come in answer"); public static boolean enter; public static string useranswer; public static string[] normalwords = { "yellow", "alphabet", "tangent", "elephant", "amusement", "cat", "eerie", "wonder", "shadows" }; public static string[] scrambledwords = { "lloeyw", "lphaabte", "natgnte", "leehpnta", "mauseenmt", "tca", "reeei", "dowenr", "shawdos" }; createwindow(){ setsize(500,300); setresizable(false); setdefaultcloseoperation(jframe.exit_on_close); setlocationrelativeto(null); field.seteditable(false); button.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { come in = true; system.out.println("you clicked button"); system.out.println(enter); } }); add(panel); panel.add(field, borderlayout.page_start); panel.add(area, borderlayout.center); panel.add(button, borderlayout.page_end); setvisible(true); } public static void setscrambledword(int i){ field.settext(scrambledwords[i]); } public void cleararea(){ area.settext(""); } }

== compares identity of objects, meaning checks if 2 references compare point same memory address.

.equals() compares objects based on values.

java string

Comments

Popular posts from this blog

java - Bypassing "final local variable defined in an enclosing type" -

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -