java - Return Value from JOptionPane indicating the button selected -
i have made alternative panel, can't buttons meant to. have tried create action int connected panel, doesn't work.
object[] choices = null; object[] options = { "criticals", "pure damage", "heal 300 points", "flee" }; 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;
also, don't know how create harm or heal has been done, saved , remain @ level next attack, instead of homecoming default.
i think need:
int action = joptionpane.showoptiondialog(null, "what do?", "action", joptionpane.default_option, joptionpane.question_message, null, options, options[0]);
you're ignoring homecoming value of method, tells button pressed.
java switch-statement joptionpane
No comments:
Post a Comment