Results 1 to 2 of 2
  1. #1
    irnie1994 is offline Member
    Join Date
    Aug 2011
    Posts
    28
    Rep Power
    0

    Default ANYCODE FOR JOPTIONPANE CANCEL and OK BUTTON TO COMPLETE?

    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    	
        	
        	
        	
        	
        	
        	
        	
        }
    }
    ---> if i click ok it will exit... And same to cancel....

    Any code for this problem??
    Last edited by Fubarable; 12-08-2011 at 04:13 AM. Reason: QUOTE TAGS CHANGED TO CODE TAGS

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: ANYCODE FOR JOPTIONPANE CANCEL and OK BUTTON TO COMPLETE?

    if i click ok it will exit
    Where is the code executing when you click on ok?

    Are there any error messages when the program exits?

Similar Threads

  1. Cancel button ? In java
    By smasm in forum New To Java
    Replies: 21
    Last Post: 10-01-2011, 06:24 AM
  2. Replies: 5
    Last Post: 08-15-2011, 06:10 PM
  3. Cancel button for exiting app
    By phearless in forum AWT / Swing
    Replies: 1
    Last Post: 01-13-2011, 07:20 PM
  4. Struts 2 cancel button
    By kirtichopra2003 in forum Advanced Java
    Replies: 0
    Last Post: 09-29-2009, 03:40 PM
  5. How should I cancel this thread ?
    By playwin2 in forum Threads and Synchronization
    Replies: 7
    Last Post: 08-27-2008, 06:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •