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

📄 mainmenu.java

📁 相册是J2me MIDLet 的一个demo程序
💻 JAVA
字号:
/*
 *	Filename: MainMenu.java
 *  - contains definition of the class MainMenu. It is a List serving as the Main Menu of Image Album  
 *  itself is the CommandListener which receives command from the List and invoke the corresponding action.
 *
 *  Application Name: Image Album Demo 
 *  Version: 2.0
 *  Release Date: 27th September, 2002
 *  Author:	Edmund Wong, Application Engineer, Metrowerks Hong Kong
 *
 *
 *  (c) Copyright. 2002. Metrowerks Corp. ALL RIGHTS RESERVED.
 *	This code is provided "AS IS" without warranty of any kind and subject to Metrowerks Sample Application
 *  End User License Agreement. NO EXTERNAL DISTRIBUTION OR COMMERCIALIZATION OF THE SOFTWARE IS PERMITTED 
 *  EXCEPT BY WRITTEN AGREEMENT OF METROWERKS."
 */

import javax.microedition.lcdui.*;
import java.util.*;


public class MainMenu extends List implements CommandListener{

	/**
     * Create screen items for Main Menu 
     */
     
     // create ticker for showing in Main Menu
   	 Ticker tickerMainMenu= new Ticker("Select View Album for viewing images at your own control! Select Slide Show for viewing images with automatic image change!");
   	  
   	 
   	 // create commands for Main Menu
   	 Command selectCommand = new Command("Select",Command.ITEM,0);    
    
     Command quitCommand = new Command("Quit",Command.EXIT,0); 
         	      
     ImageAlbum imageAlbumReference; // reference for main object ImageAlbum
         
     Form ImageDBStatusCheckForm; // create Form for showing Image Database Status Information


	/**
     *  Constructor for MainMenu
     */
	
	public MainMenu(ImageAlbum imageAlbumReference) {

       
		super("Image Album V2.0. Select your choice!", List.EXCLUSIVE); //Create a List as main menu
	
		this.imageAlbumReference = imageAlbumReference;	
	
		/**
     	 * Appending items to Select List (Main Menu)
     	 */
     	 
        setCommandListener(this);  
                  
        append("View Album", null);
        
        append("Slide Show", null);
        
        append("Options", null);
        
        append("Download from specified URL", null);
        
        append("Image Database Status Information", null);
        
        append("Help",null);
        
        append("About Image Album",null);
        
        
	   /**
     	* Add command and ticker for the Main Menu 
     	*/
     	
		addCommand(selectCommand);
		
		addCommand(quitCommand);
		
		setTicker(tickerMainMenu);
		
			
	}	
	
	
	/**
     * Implementation for CommandListener
     */
     
    public void commandAction(Command c, Displayable s) {
    
    	/** 
    	 *	Initiate the correspoding action according to user's choice in main menu
    	 */
    	 
       	if (c==selectCommand) { 
        	
        		
        	switch (this.getSelectedIndex())
    		{ 	
    			case 0:		// start viewing album manually
    			
    			ImageAlbum.slideShowing = false;
    			
    			//initialize image reference on Canvas 
    			imageAlbumReference.slideShowCanvas.img = (Image)imageAlbumReference.imageVector.elementAt(0);
    			
    			ImageAlbum.myDisplay.setCurrent(imageAlbumReference.viewAlbumCanvas);
    			
    			ImageAlbum.imageShowCounter = -1;   // set to -1, will be increased to 0 in changeNextPhoto 
    									 // function for showing the first image 
    			    			   			
    			imageAlbumReference.changeNextPhoto(imageAlbumReference.viewAlbumCanvas);
    			
    			break;
    			
    			    
    			    	
    	
    			case 1:		// start viewing album in slide show mode
    			
    			ImageAlbum.slideShowing = true;   			    			  			
    			
				
				ImageAlbum.imageShowCounter = -1; // set to -1, will be increased to 0 in changeNextPhoto 
									   // function for showing the first image
				
				//initialize image reference on Canvas
									   
				imageAlbumReference.slideShowCanvas.img = (Image)imageAlbumReference.imageVector.elementAt(0);
																	   
				ImageAlbum.myDisplay.setCurrent(imageAlbumReference.slideShowCanvas);
				
				imageAlbumReference.slideShow(imageAlbumReference.slideShowCanvas,0);
    			
    			break;    			
    			
    			
    			
    			
    			case 2:	// show optionsInputForm for user to enter options 
    			
    			ImageAlbum.myDisplay.setCurrent(imageAlbumReference.optionsInputForm);
    			
    			break;
    			
    			
    			
    			
    			case 3: // show downloadFromURLForm for user to enter URL and download Image from that specified URL
    			
    			ImageAlbum.myDisplay.setCurrent(imageAlbumReference.downloadFromURLForm);
    			    			
    			break;
    			
    			
    			   
    			    			
    			case 4:  // show ImageDBStatusCheckForm for user to check the RecordStore Status information
    			
    			ImageDBStatusCheckForm = new Form("Image Database Status:");
    			
    			ImageDBStatusCheckForm.addCommand(ImageAlbum.mainMenuCommand);
    			
    			ImageDBStatusCheckForm.setCommandListener(this);
    			
    			ImageDBStatusCheckForm.append("- Total no. of Images in Album: \n" + ImageAlbum.totalImageNumber + "\n");
    			
    			ImageDBStatusCheckForm.append("- No. of Images from installed JAR package: \n" + ImageAlbum.imageNumberInJAR + "\n");
    			
    			ImageDBStatusCheckForm.append("- No. of Images saved in Record Store of phone: \n" + ImageAlbum.imageNumberInRecordStore + "\n");
    			
    			    			
    			// open the RecordStore "ImageDB"      			
    			imageAlbumReference.rmsOperations.openRecordStore("ImageDB", false);  // false -> no enumerate needs
    			
    			
    			// get size of RecordStore used for storing Images and append to the ImageDBStatusCheckForm    			
    			ImageDBStatusCheckForm.append("- Memory used for storing Images in Record Store:\n " + imageAlbumReference.rmsOperations.getSize() + " Bytes \n");
					 						 
				
				imageAlbumReference.rmsOperations.closeRecordStore();    // close the "ImageDB" RecordStore   			
       			       			      			
       			
       			// open the RecordStore "DescriptionsDB"        			
       			imageAlbumReference.rmsOperations.openRecordStore("DescriptionsDB", false);  // false -> no enumerate needs
       			
       			
       			// get size of RecordStore used for storing descriptions and append to the ImageDBStatusCheckForm						
				ImageDBStatusCheckForm.append("- Memory used for storing descriptions:\n " + imageAlbumReference.rmsOperations.getSize() + " Bytes \n");
					 
					 
				// get size of RecordStore available and append to the ImageDBStatusCheckForm				
				ImageDBStatusCheckForm.append("- Memory available in Record Store:\n " + imageAlbumReference.rmsOperations.getSizeAvailable() + " Bytes \n");
											
				
				imageAlbumReference.rmsOperations.closeRecordStore();    // close "DescriptionsDB" RecordStore 
								
				
				ImageAlbum.myDisplay.setCurrent(ImageDBStatusCheckForm);				 			
    			    			
    			break;
    			
    			
    			
    			
    			case 5:	// show Help Info when chosen in Main Menu
    			
    			HelpDisplayForm helpDisplayForm = new HelpDisplayForm(imageAlbumReference);
    			
    			ImageAlbum.myDisplay.setCurrent(helpDisplayForm);
    			
    			helpDisplayForm = null;
    			    			
    			break;
    			
    			
    			
    			
    			case 6: // show About Info when chosen in Main Menu
    			
    			Alert aboutAlert = new Alert("About","Image Album Demo \nVersion 2.0 \nSeptember 2002 \n\nBy Edmund Wong \nMetrowerks Corp.", null, AlertType.INFO);
    			
    			aboutAlert.setTimeout(Alert.FOREVER);  // Set display time for About Alert message
    			    			      			
    			ImageAlbum.myDisplay.setCurrent(aboutAlert, s);
    			
    			aboutAlert = null;
    			
    			break;
    			
    			
			}
			
		}
		

		/** 
    	 *	Quit this J2ME application when quitCommand is chosen from main menu
    	 */		
    	 
		if (c==quitCommand) {
		
			imageAlbumReference.notifyDestroyed();
		}
				
				
		/** 
    	 *	For ImageDBStatusCheckForm, for user to return to Main Menu after viewing RecordStore status info
    	 */
		
		if (c == ImageAlbum.mainMenuCommand) {
		
			ImageAlbum.myDisplay.setCurrent(this);
			
			ImageDBStatusCheckForm = null;
		}
	
	}
	
} 

	

⌨️ 快捷键说明

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