java - javax.swing.JOptionPane cancel button loop -


i trying write while loop allow app keep running until user pushes cancel on joptionspane . how do this? i'm using javax.swing.joptionpane cancel button loop.

this code far cancel button not work.

 import java.io.*;  import javax.swing.joptionpane;  public class mytype2 {      public static void main(string[] args)     {      string strchoice, strtrystrig, strtryint, strtrydouble;     int choice, tryint;     double trydouble;     boolean done = false;      while(!done)     {         try         {             strchoice = joptionpane.showinputdialog(null,"whats type?" + "\n\n1) string\n2) interger\n3) double\n4) quit program\n ");             choice = integer.parseint(strchoice);                      switch(choice)                     {                     case 1:                         if (choice == 1)                             joptionpane.showmessagedialog(null,"correct , input can saved string.", "result",joptionpane.information_message);                         break;                          case 2:                         if (choice == 2);                             joptionpane.showmessagedialog(null,"correct ", "result",joptionpane.information_message);                          break;                          case 3:                         if (choice == 3)                             joptionpane.showmessagedialog(null,"correct .", "result",joptionpane.information_message);                          break;                          case 4:                         if (choice == 4)                             done = true;                         break;                          default:                         if(choice<=0 || choice>=5) throw new numberformatexception();                         break;                     }         }      catch (numberformatexception e)     {         joptionpane.showmessagedialog(null,"your number not in proper format.", "error",joptionpane.information_message);     }         }     } } 

javax.swing gui elements "run" until close them. if put in infinite loop want cancel via button, think won't able gui unresponsive unless explicitely take care of threading.

if so, can switch loop condition false via buttonclick..


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -