⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagealbum.java

📁 相册是J2me MIDLet 的一个demo程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }
    

    /**
     * Called by the framework before the application is unloaded
     */
     
    protected void destroyApp(boolean unconditional) {
    	    
    }
    
    
    /**
     * Implementation for CommandListener
     */
     
    public void commandAction(Command c, Displayable s) {
        	    	
    	
    	/** 
    	 *	Stop slide show and show Main Menu when it is chosen during slide show
    	 */
    	 
    	if (c==mainMenuCommand && s==slideShowCanvas) {
    	
    		if (slideShowing==true) {
    		
    		slideShowing=false;
		
			slideTask.cancel();
			
			slideTask = null;
			
    		}
    		
    		myDisplay.setCurrent(selectList);
    		    		
    	}
    	
    	
    	/** 
    	 *	Show Main Menu when it is chosen when viewing Album manually or in options input form
    	 *  or in displaying Help 
    	 */
    	 
    	if (c==mainMenuCommand) {
    	
    		myDisplay.setCurrent(selectList);
    	}
    	
    	
    	/** 
    	 *	Change to next image when command next is chosen
    	 */
    	 
    	if (c==nextImageCommand) {
    	
    		changeNextPhoto((PhotoCanvas)s);  
    	
    	}
        
        
        /** 
    	 *	Change to previous image when command previous is chosen
    	 */
    	 
        if (c==previousImageCommand) {
    	
    		changePreviousPhoto((PhotoCanvas)s);    	
    	
    	}
    	
    	
    	/** 
    	 *	Delete the currently showing image and description when delete Command is chosen
    	 */
    	 
        if (c==deleteImageCommand) {
        
        	int x = 0; // as counter for image/descriptions Record in Record Store
        
          	if (imageShowCounter > (imageNumberInJAR - 1) ) {   //image to be deleted resides in RecordStore
        
        	boolean deleteLastImage = true;
        
        	if (imageShowCounter != (totalImageNumber - 1) ) {  // if the image to be deleted is not last image
        		
        	deleteLastImage = false;
        	
        	}
        
        	imageVector.removeElementAt(imageShowCounter);
        	
        	descriptionsVector.removeElementAt(imageShowCounter);
        	
        	//open the RecordStore "ImageDB"
        	
        	rmsOperations.openRecordStore("ImageDB", true);
        	
												
			//delete the image Record
							
			rmsOperations.deleteRecord(rmsOperations.getRecordIDAtSequenceNo(imageShowCounter + 1 - imageNumberInJAR));
							
			
			// close RecordStore "ImageDB"
										
			rmsOperations.closeRecordStore();
			
       					
					
			//open the RecordStore "DescriptionsDB"
        	
        	rmsOperations.openRecordStore("DescriptionsDB", true);
        	       		                 
		                 
		    //delete the description Record
							
			rmsOperations.deleteRecord(rmsOperations.getRecordIDAtSequenceNo(imageShowCounter + 1));
		               		                 
					
			// close RecordStore "DescriptionsDB" 
			
			rmsOperations.closeRecordStore();
			
					    	
        	
        	totalImageNumber--;
        	
        	imageNumberInRecordStore--;
        	
        	Alert deleteOKAlert = new Alert("Delete OK!", "Image "+ (imageShowCounter+1) + " is deleted! \n", null, AlertType.CONFIRMATION);
																		
			deleteOKAlert.setTimeout(2500);
				
			ImageAlbum.myDisplay.setCurrent(deleteOKAlert);
					
			refreshPhoto((PhotoCanvas)s, deleteLastImage);
		
			
		  } 
		  
		  
		  else {  // image selected for delete is resided in JAR package, which is not allowed to be deleted
		  
		  	Alert cannotDeleteAlert = new Alert("Cannot Delete!", "Image in original JAR package cannot be deleted! \n", null, AlertType.ERROR);
																		
			cannotDeleteAlert.setTimeout(Alert.FOREVER);
				
			ImageAlbum.myDisplay.setCurrent(cannotDeleteAlert,s);
		  
		  }
				   	
    	
    	}
        
        
        
        
        /** 
    	 *	Edit the description of the currently showing image when edit Description Command is chosen
    	 */
    	 
        if (c==editDescriptionCommand) {
        
        	Form editDescriptionForm = new Form ("Edit Description");
        	
        	editDescriptionTextField = new TextField("Enter your own description for this image in text box below and choose 'Save Description' Command. (max. 100 characters):", (String)descriptionsVector.elementAt(imageShowCounter) , 100, TextField.ANY);
        	       	       	       	
        	        	
        	editDescriptionForm.setCommandListener(this);
        	        	
        	editDescriptionForm.append(editDescriptionTextField); 
        	        	
        	editDescriptionForm.addCommand(saveEditedDescriptionCommand);
        	
        	editDescriptionForm.addCommand(backToViewAlbum);
        	
        	editDescriptionForm.addCommand(mainMenuCommand);
        	
        	ImageAlbum.myDisplay.setCurrent(editDescriptionForm);
        
          	   	
    	}
    	
    	
    	/** 
    	 *	for returning back to image view when backToViewAlbum Command is chosen from viewAlbumCanvas's edit 
    	 *  description view,
    	 */
    	
    	if (c==backToViewAlbum) {	
    	
    		ImageAlbum.myDisplay.setCurrent(viewAlbumCanvas);
    		
    		viewAlbumCanvas.repaint();
    	
    	
    	}
    	
    	
    	/** 
    	 *	for saving edited image description when saveEditedDescriptionCommand is chosen from viewAlbumCanvas's 
    	 *  edit description view
    	 */
    	    	
    	if (c==saveEditedDescriptionCommand) {
    	
    			
    		// store the description into the Vector descriptionsVector for immediate showing use
			descriptionsVector.setElementAt(editDescriptionTextField.getString(), imageShowCounter);
				
			//update Canvas with newly edited descriptions 
			viewAlbumCanvas.description = (String)descriptionsVector.elementAt(imageShowCounter);
						
    		    		
    		// open the RecordStore "DescriptionsDB"
    		
    		rmsOperations.openRecordStore("DescriptionsDB", true);
    						
				
			// convert default description string into byte array 
				
			try {
		
				byteArray = StringByteOperations.stringToByteConvertion(editDescriptionTextField.getString());
				
			}
				
			catch(Exception e) {
			
				System.out.println("Exception: " + e.toString());		
			}
							
				
			// write the byte array of the string into the editing record in RecordStore and set viewAlbumCanvas as the next screen				
			rmsOperations.setRecord(rmsOperations.getRecordIDAtSequenceNo(imageShowCounter + 1), byteArray, "Save OK!", viewAlbumCanvas);
						
				
			// close RecordStore "DescriptionsDB"
				
			rmsOperations.closeRecordStore();
				
							
			// refresh the screen with updated viewAlbumCanvas - new description appended
			viewAlbumCanvas.repaint();
				
			viewAlbumCanvas.serviceRepaints(); 
						
				
			byteArray = null;    		    	
    	
    	}
        			
		
		
		
		/** 
    	 *	Pause the slide show when pause is chosen during slide show
    	 */	
    	 
		if (c==pauseCommand && slideShowing==true) {
		
				slideShowing=false;
		
				slideTask.cancel();
			
				slideTask = null;
		
		}
		
		
		
		/** 
    	 *	Return to slide show when continue slide show is chosen during slide show is paused
    	 */	
    	 
		if (c==continueSlideShowCommand && slideShowing==false) {
						
				slideShowing=true;
				
				slideShow(slideShowCanvas,1200); //start slide show with 1.2 second delay
				
		}
		 	
    
    }
    
    
    
                  
    /**
	 *  Method for starting the slide show after the specified time delay
	 */	    
	 	
    public void slideShow(PhotoCanvas slideShowCanvas, int slideShowStartDelay) {
    
    		timerTime = Integer.parseInt(optionsInputForm.slideDisplayTimeEntry.getString(),10)*1000;
    
    		slideTask = new MyTimerTask(slideShowCanvas, this);
        
    		t.schedule(slideTask,slideShowStartDelay,timerTime);
              
	}
	
	
			
	/**
	 *  Method for changing to next image
	 */
	 
	public void changeNextPhoto(PhotoCanvas photo) {
	
			imageShowCounter++; // increment the counter to the image no. of next image to be displayed
			
			//show end of show alert if reach end of album and looping is not selected
			
			if (imageShowCounter == totalImageNumber && optionsInputForm.loopChoice.isSelected(0)==false) {
			
					imageShowCounter--;
					
					// show end of slide show alert and stop slide show if it is showing slide show			
					if (slideShowing == true) {
			
					slideShowing = false;
					
					slideTask.cancel();
			
					slideTask = null;
					
					myDisplay.setCurrent(endSlideShowAlert,photo);
													
					}
					
					// show end of album alert if user is viewing album manually 			
					else {
					
					myDisplay.setCurrent(endOfAlbumAlert,photo); 
															
					}	
			
			} else {
			
					// show next photo, show first image of album if looping is selected and end of album is reached
					if (imageShowCounter == totalImageNumber && optionsInputForm.loopChoice.isSelected(0)==true) {
			
					imageShowCounter = 0;
			
					}
		
        			       			
        			photo.img = (Image)imageVector.elementAt(imageShowCounter); //change to next image
        			        			 			
        			photo.description = (String)descriptionsVector.elementAt(imageShowCounter); //change to next image's description
        			
        			photo.imageID = imageShowCounter + 1; //change to next image's imageID, +1 because imageShowCounter is for array
               			
					photo.originX = 0;
        
        			photo.originY = 0;
														
					photo.repaint();	
					
								
			
			}
			
	}
	
	
	
	/**
	 *  method for changing to previous image
	 */
	 
	public void changePreviousPhoto(PhotoCanvas photo) {
	
			imageShowCounter--;
			
			// show reach of start of album alert 	
			
			if (imageShowCounter < 0 && optionsInputForm.loopChoice.isSelected(0)==false) {
			
				imageShowCounter++;
			
				myDisplay.setCurrent(startOfAlbumAlert,photo);
				
							
			}
			
			// show previous image, return to last image of album if start of album is reached and looping is selected 	
			else {
			
				if (imageShowCounter < 0 && optionsInputForm.loopChoice.isSelected(0)==true) {
				
				imageShowCounter=totalImageNumber-1;
				
				}
				        	    
        	    
        	    photo.img = (Image)imageVector.elementAt(imageShowCounter); //showing previous image
        	            	           	    
        	    photo.description = (String)descriptionsVector.elementAt(imageShowCounter); //change to previous image's description
                                   	 			
				photo.imageID = imageShowCounter + 1; //change to next image's imageID, +1 because imageShowCounter is for array 
				
				photo.originX = 0;
        
        		photo.originY = 0;				
						
				photo.repaint();	
			
			}
			
	}
	
	
	/**
	 *  Method for refreshing image, for use after delete image action
	 */
	 
	public void refreshPhoto(PhotoCanvas photo, boolean deleteLastImage) {
	
	
			if (deleteLastImage == false) {	 // not last image deleted
	
			photo.img = (Image)imageVector.elementAt(imageShowCounter); // showing new image which moved to location 
																	// imageShowCounter in image Vector 
																	// after delete
		
			photo.description = (String)descriptionsVector.elementAt(imageShowCounter);  // showing new description which moved 
																	// to location imageShowCounter in image Vector 
																	// after delete
			
			photo.imageID = imageShowCounter + 1; // image no. as shown to user (1 larger than the imageShowCounter index)
		
			}
		
		
			if (deleteLastImage == true) {  // last image deleted
	
			photo.img = (Image)imageVector.elementAt(--imageShowCounter); //showing image previous to the last image deleted 
																	  //in image Vector by updating the imageShowCounter
																			 		
			photo.description = (String)descriptionsVector.elementAt(imageShowCounter);  //showing description previous 
																	  //to the last description deleted in image Vector
		
			photo.imageID = imageShowCounter + 1; // image no. as shown to user (1 larger than the imageShowCounter index)
		
			}
	
			photo.repaint();
	
	}			
	
	

	
}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -