Results 1 to 2 of 2
- 12-08-2011, 12:24 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 28
- Rep Power
- 0
ANYCODE FOR JOPTIONPANE CANCEL and OK BUTTON TO COMPLETE?
---> if i click ok it will exit... And same to cancel....Java Code:import javax.swing.*; public class irnie { public static void main(string[] args) { int arr[] = new int [10]; int i, j, inp, choose, select; string search, display; int a = 0; int count = 0; int delete = 0; int size = 0; int prompt = joptionpane.no_option; search = ""; display = ""; //initialize value of array to -1 for(i=0; i<10; i++){ arr[i] = -1; } choose = integer.parseint(joptionpane.showinputdialog(null,"pag pili lang\nnaa sa ubos and pilian:\n \n[1] insert \n[2] size \n[3] delete \n[4] search \n[5] display \n[6] exit","menu",joptionpane.question_message)); if (choose>6) joptionpane.showmessagedialog(null,"wala man siya sa pilianan","error",joptionpane.error_message); //main loop while(choose != 6){ if(choose == 1){ for(i=0; i<10; i++){ if(arr[i] == -1){ count++; } } if(count > 0){ select = integer.parseint(joptionpane.showinputdialog(count + " spaces in the array are available. \n \nselect your choice below: \n[1] insert to head \n[2] insert to tail\n \nenter the number of your choice:")); while((select>2)||(select<1)){ joptionpane.showmessagedialog(null,"wala siya sa pilianan","error",joptionpane.error_message); select = integer.parseint(joptionpane.showinputdialog(count + " ang nabilin nga bakante. \n \nselect your choice below: \n[1] insert to head \n[2] insert to tail\n \nenter the number of your choice:")); } inp = integer.parseint(joptionpane.showinputdialog("enter number")); if(select == 1){ for(i=0; i<10; i++){ if(arr[i] == -1){ a = i; break; } } for(i=a; i>0; i--){ j = i - 1; arr[i] = arr[j]; } arr[0] = inp; } else if(select == 2){ for(i=0; i<10; i++){ if(arr[i] == -1){ a = i; break; } } arr[a] = inp; } } else joptionpane.showmessagedialog(null,"no space in the array available.","status",joptionpane.information_message); }//end insert //size if(choose == 2){ for(i=0; i<10; i++){ if(arr[i] != -1) size++; } joptionpane.showmessagedialog(null,"size: " + size,"size", joptionpane.information_message); }//end size //delete if( (choose == 3) || (prompt == joptionpane.yes_option) ){ inp = integer.parseint(joptionpane.showinputdialog(null,"enter the number you want to delete: ","delete",joptionpane.question_message)); for(i=0; i<10; i++){ if(arr[i] == inp){ arr[i] = -1; delete++; } } if(delete>0){ for(i=0; i<10; i++){ for(j=i+1; j<10; j++){ if(arr[i] == -1){ arr[i] = arr[j]; arr[j] = -1; } } } } else joptionpane.showmessagedialog(null,"number not found!","error",joptionpane.warning_message); }//end delete //search if(choose == 4){ inp = integer.parseint(joptionpane.showinputdialog("enter the number you want to search")); for(i=0; i<10; i++){ if(arr[i] == inp){ search += i + " "; } } if(search.length() > 0) joptionpane.showmessagedialog(null,"index/es: " + search, "index",joptionpane.information_message); else joptionpane.showmessagedialog(null,"number not found.","error",joptionpane.error_message); }//end search //display if(choose == 5){ for(i=0; i<10; i++){ display += arr[i] + " "; } joptionpane.showmessagedialog(null,"stack items: \n" + display, "display", joptionpane.information_message); }//end display choose = integer.parseint(joptionpane.showinputdialog(null,"please enter a number\nfrom the choices below:\n \n[1] insert \n[2] size \n[3] delete \n[4] search \n[5] display \n[6] exit","menu",joptionpane.question_message)); count = 0; delete = 0; size = 0; prompt = joptionpane.no_option; search = ""; display = ""; }//end of loop } }
Any code for this problem??Last edited by Fubarable; 12-08-2011 at 04:13 AM. Reason: QUOTE TAGS CHANGED TO CODE TAGS
- 12-14-2011, 10:23 PM #2
Similar Threads
-
Cancel button ? In java
By smasm in forum New To JavaReplies: 21Last Post: 10-01-2011, 06:24 AM -
To prevent the user to close JOPTIONPANE USING the X button IN IT
By vjoseph in forum AWT / SwingReplies: 5Last Post: 08-15-2011, 06:10 PM -
Cancel button for exiting app
By phearless in forum AWT / SwingReplies: 1Last Post: 01-13-2011, 07:20 PM -
Struts 2 cancel button
By kirtichopra2003 in forum Advanced JavaReplies: 0Last Post: 09-29-2009, 03:40 PM -
How should I cancel this thread ?
By playwin2 in forum Threads and SynchronizationReplies: 7Last Post: 08-27-2008, 06:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks