java - JOptionPane.showOptionDialog not working -
i trying create little popup game. have added story , worked fine, untill added piece of code:
object[] choices = null; object[] options = { "caitlyn", "warwick", "teemo", "olaf", "ashe" }; int select = joptionpane.showoptiondialog(null, "who want fighting against?", "champion selection", joptionpane.closed_option, joptionpane.question_message, null, options, action );
now, these options appear on every optiondialog appears. how prepare this?
this code
object[] choices = null; object[] options = { "caitlyn", "warwick", "teemo", "olaf", "ashe" }; int select = joptionpane.showoptiondialog(null, "who want fighting against?", "champion selection", joptionpane.closed_option, joptionpane.question_message, null, options, action ); switch (select) { case 0: int cait = 0; cait++; joptionpane.showmessagedialog(null, "you fighting against next champion:" + " " + caitlyn.champion + " " + "\n level" + " " + caitlyn.level + " " + "\n , " + caitlyn.type + "-champion"); joptionpane.showmessagedialog(null, "you have started 2000hp, caitlyn has 1700hp."); // health newchamp.health = 2000; caitlyn.enemyhealth = 1700; //begin object[] choices1 = null; object[] options1 = { "criticals", "pure damage", "heal 300 points", "flee" }; int action = joptionpane.showoptiondialog(null, "what do?", "action", joptionpane.default_option, joptionpane.question_message, null, options, options[0]); switch (action) { case 0: int criticals = (int) (math.random()*500); criticals++; caitlyn.enemyhealth = (caitlyn.enemyhealth-criticals); joptionpane.showmessagedialog(null, "caitlyn has" +" " + caitlyn.enemyhealth + "hp left"); break; case 1: int puredamage = (int) (math.random()*300); puredamage++; caitlyn.enemyhealth = (caitlyn.enemyhealth-puredamage); joptionpane.showmessagedialog(null, "caitlyn has" + " " + caitlyn.enemyhealth + "hp left"); break; case 2: int heal = 300; heal++; newchamp.health = (newchamp.health+heal); joptionpane.showmessagedialog(null, "you have"+ " " + newchamp.health + "hp points!"); break; case 3: string flee; joptionpane.showmessagedialog(null, "you failed flee battle, improve luck next round!"); break; } joptionpane.showmessagedialog(null, "it's caitlyn's turn now!"); joptionpane.showmessagedialog(null, "caitlyn used damaging attack!"); int enemydamage = (int) (math.random()*350); newchamp.health = (newchamp.health - enemydamage); joptionpane.showmessagedialog(null, "you have" + " " + newchamp.health +" "+ " hp left"); joptionpane.showmessagedialog(null, "it's turn again!"); object[] choices2 = null; object[] options2 = { "criticals", "pure damage", "heal 300 points", "flee" }; int action1 = joptionpane.showoptiondialog(null, "what do?", "action", joptionpane.default_option, joptionpane.question_message, null, options, options[0]); switch (action1) { case 0: int criticals = (int) (math.random()*700); criticals++; caitlyn.enemyhealth = (caitlyn.enemyhealth-criticals); joptionpane.showmessagedialog(null, "caitlyn has" +" " + caitlyn.enemyhealth + "hp left"); break; case 1: int puredamage = (int) (math.random()*300); puredamage++; caitlyn.enemyhealth = (caitlyn.enemyhealth-puredamage); joptionpane.showmessagedialog(null, "caitlyn has" + " " + caitlyn.enemyhealth + "hp left"); break; case 2: int heal = 300; heal++; newchamp.health = (newchamp.health+heal); joptionpane.showmessagedialog(null, "you have"+ " " + newchamp.health + "hp points!"); break; case 3: string flee; joptionpane.showmessagedialog(null,"you have failed flee battle, improve luck next round!"); break; } joptionpane.showmessagedialog(null, "it's caitlyn's turn again!"); joptionpane.showmessagedialog(null, "caitlyn nail critical!"); int enemydamage1 = (int) (math.random()*650); newchamp.health = (newchamp.health - enemydamage); joptionpane.showmessagedialog(null, "you have" + " " + newchamp.health +" "+ " hp left"); if (caitlyn.enemyhealth < newchamp.health){ joptionpane.showmessagedialog(null, "caitlyn injured strength go on battle. victorious!"); } else joptionpane.showmessagedialog(null, "you injured go on battle. defeated."); break; case 1: int war = 0; war++; joptionpane.showmessagedialog(null, "warwick still beingness made. window exit program."); break; case 2: int teem = 0; teem++; joptionpane.showmessagedialog(null, "teemo still beingness made. window exit program."); break; case 3: int ola = 0; ola++; joptionpane.showmessagedialog(null, "olaf still beingness made. window exit program."); break; case 4: int ash = 0; ash++; joptionpane.showmessagedialog(null, "ashe still beingness made. window exit program."); break; } } }
did note part of code
object[] choices2 = null; object[] options2 = { "criticals", "pure damage", "heal 300 points", "flee" }; int action1 = joptionpane.showoptiondialog(null, "what do?", "action", joptionpane.default_option, joptionpane.question_message, null, **options**, options[0]);
the ** indicate probable issue. shouldn't options2
? (there other place same probable mistake)
java swing joptionpane
No comments:
Post a Comment