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

📄 j2megameapiclientsimplemidlet.java

📁 J2ME 的手机实例模型
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * J2MEGameAPIClientMidlet.java
 *
 * Copyright by ASTRI, Ltd., (WISE Group)
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of ASTRI, Ltd. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you
 * entered into with ASTRI.
 */

import java.io.*;

import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Image;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import javax.microedition.io.Connector;

import org.astri.wise.wiseg.gameapi.simple.*;
import org.astri.wise.wiseg.gameapi.simple.data.*;


/**
 * Client Midlet for J2ME Game API v1.0
 * 
 * <b>IMPORTANT! </b> Make sure that your class has declared all the necessary
 * field for population into <b>public </b>.
 * 
 * @author Dennis Li
 * @version 1.0 2005-3-23
 * @since 1.0
 */
public class J2MEGameAPIClientSimpleMidlet extends MIDlet implements CommandListener {
	
	// Need to fill in valid connection account and password with 
	// values obtained from GC Operator
	
    private static final String SEPERATOR = "-";
    final String USER_PROPERTY = "user";
    final String PASS_PROPERTY = "pass";
    final String LOCATION_PROPERTY = "simpleAPIlocation";

    WiseGAgent agent = null;
    Display display = null;
    
	Form mainMenuForm = new Form("Main Menu");
	Form inputQueryForm = new Form("Input Query");
 	Form productInfoForm = new Form("Product Info");
 	Form issueOrderForm = new Form("Issue Order");	
 	Form orderResultForm = new Form("Issue Order Result");
 	Form checkOrderStatusForm = new Form("Check Order Status");
 	Form orderStatusForm = new Form("Order Status");
 	
    Command getProductsCmd = new Command("Get Products", Command.ITEM, 1);
    Command sendQueryCmd = new Command("Send", Command.ITEM, 1);
    Command issueOrderCmd = new Command("Issue Order", Command.ITEM, 1);
    Command checkStatusCmd = new Command("Check Order Status", Command.ITEM, 1);
    Command exitCmd = new Command("Exit", Command.EXIT, 1);
    Command goToMainMenuCmd = new Command("Menu", Command.BACK, 1);
    Command sendOrderCmd = new Command("Send", Command.OK, 1);
    Command sendCheckStatusCmd = new Command("Send", Command.OK, 1);
    
    boolean isMainMenuFormInitialized = false;
    boolean isProductInfoFormInitialized = false;
    boolean isInputQueryFormInitialized = false;
    boolean isIssueOrderFormInitialized = false;
    boolean isOrderResultFormInitialized = false;
    boolean isCheckOrderStatusFormInitialized = false;
    boolean isOrderStatusFormInitialized = false;
    
    TextField transactionIdTF;
    TextField totalPriceTF;
    TextField unitPriceTF;
    TextField currencyTF;
    TextField productIDTF;
    TextField payerMobileNoTF;
    TextField payerCarrierNameTF;
    TextField receiverMobileNoTF;
    TextField receiverCarrierNameTF;
    //TextField handsetModelTF;
    
    ChoiceGroup typeGroup;
    ChoiceGroup categoryGroup;
    
    
    /**
     * 
     */
    public J2MEGameAPIClientSimpleMidlet() {
        super();
        display = Display.getDisplay(this);
    }    
    
    /**
     * (non-Javadoc)
     * 
     * @see javax.microedition.midlet.MIDlet#startApp()
     */
    protected void startApp() throws MIDletStateChangeException {
        new Thread(new Runnable() {
            public void run() {
                try {
                    doTest();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
    
    /**
     * (non-Javadoc)
     * 
     * @see javax.microedition.midlet.MIDlet#pauseApp()
     */
    protected void pauseApp() {
        // TODO Auto-generated method stub

    }

    /**
     * (non-Javadoc)
     * 
     * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
     */
    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    }

    public void commandAction(Command c, Displayable s) {            
        if (c == exitCmd) {
            try {
                destroyApp(false);
            } catch (MIDletStateChangeException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            notifyDestroyed();
        }
        
        if (c == goToMainMenuCmd) {
	        showMainMenuForm();
    	}
    	
        if (c == sendQueryCmd) {
	    	handleSendQuery();
    	}
    	
        if (c == sendOrderCmd) {
	    	handleSendOrder();
    	}
    	
        if (c == sendCheckStatusCmd) {
	    	handleSendCheckStatus();
    	}
    	    	
    }        

    public void doTest() throws Exception {
        String location = this.getAppProperty(LOCATION_PROPERTY);
        String user = this.getAppProperty(USER_PROPERTY);
    	String pass = this.getAppProperty(PASS_PROPERTY);
    
        AuthInfo auth = new AuthInfo(location, user, pass);
        agent = new WiseGAgent(auth);
        
        System.out.println("-----Setup-----");
        System.out.println("location = " + location);
        System.out.println("user = " + user);
        System.out.println("pass = " + pass);
        
        agent.login();
                
        showMainMenuForm();
    }
   
    private void showMainMenuForm() {
	    System.out.println("-----Main Menu-----");
	    if (!isMainMenuFormInitialized) {
		    initMainMenuForm();
	    }
	    
		display.setCurrent(mainMenuForm);
    }
    
    private void initMainMenuForm(){
	    System.out.println("-----Init Main Menu-----");
        ItemCommandListener icl = new ItemCommandListener() {
		    public void commandAction(Command cmd, Item item) {            
		        if (cmd == getProductsCmd) {
			        showInputQueryForm();
		        }
		        if (cmd == issueOrderCmd) {
			        showIssueOrderForm();
		        }
		        if (cmd == checkStatusCmd) {
			        showCheckOrderStatusForm();
			        
		        }		        
		    }        
        };
        
		StringItem getProductsStrItem = 
			new StringItem("", "Get Products", Item.PLAIN);    
		getProductsStrItem.setDefaultCommand(getProductsCmd);
 		getProductsStrItem.setItemCommandListener(icl);  

		StringItem issueOrderStrItem = 
			new StringItem("", "Issue Order", Item.PLAIN);    
		issueOrderStrItem.setDefaultCommand(issueOrderCmd);
 		issueOrderStrItem.setItemCommandListener(icl);  

		StringItem checkStatusStrItem = 
			new StringItem("", "Check Order Status", Item.PLAIN);    
		checkStatusStrItem.setDefaultCommand(checkStatusCmd);
 		checkStatusStrItem.setItemCommandListener(icl);  
 		 		
        mainMenuForm.append(getProductsStrItem);
        mainMenuForm.append("\n");
        mainMenuForm.append(issueOrderStrItem);
        mainMenuForm.append("\n");
        mainMenuForm.append(checkStatusStrItem);
        mainMenuForm.append("\n");
        mainMenuForm.addCommand(exitCmd);
		
		mainMenuForm.setCommandListener(this);
		
		isMainMenuFormInitialized = true;
    }

    private void showInputQueryForm() {
	    System.out.println("-----Input Query-----");
	    if (!isInputQueryFormInitialized) {
		    initInputQueryForm();
	    }
	    
        String[] categoryList = null;
        System.out.println("Category List: ");
        try {
            Category[] categories = agent.getAllCategories();
            categoryList = new String[categories.length];
            for (int i=0; i<categories.length; i++) {
                int j = categories.length - 1 - i;
                categoryList[j] = categories[i].getId() + SEPERATOR + categories[i].getName();
                System.out.print(categoryList[j] + " ");
            }
        } catch (WiseGAgentException e) {
            e.printStackTrace();
        } catch (WiseGAgentInternalException e) {
            e.printStackTrace();
        }

        categoryGroup = new ChoiceGroup("Category", ChoiceGroup.EXCLUSIVE, categoryList, null);
        
        // The type ID are defined by GC server
        String[] typeList = {WiseGAgentConstants.TYPE_TONE_MONOPHONIC + SEPERATOR + "Monotone", 
                             WiseGAgentConstants.TYPE_TONE_POLYPHONIC + SEPERATOR + "Polytone", 
                             WiseGAgentConstants.TYPE_TONE_TRUE + SEPERATOR + "Truetone", 
                             WiseGAgentConstants.TYPE_WALLPAPER + SEPERATOR + "Wallpaper"};
        typeGroup = new ChoiceGroup("Product Type", ChoiceGroup.EXCLUSIVE, typeList, null);
        
	    //handsetModelTF = new TextField("Handset Model: ", "Nokia_6230", 20, TextField.ANY);

	    inputQueryForm.deleteAll();
        inputQueryForm.append(typeGroup);
        inputQueryForm.append(categoryGroup);
        //inputQueryForm.append(handsetModelTF);
        
		display.setCurrent(inputQueryForm);
    }

    private void initInputQueryForm() {
	    System.out.println("-----Init Input Query-----");
	    inputQueryForm.addCommand(goToMainMenuCmd);
	    inputQueryForm.addCommand(sendQueryCmd);
		inputQueryForm.setCommandListener(this);
		
		isInputQueryFormInitialized = true;		
    }
    
    private void handleSendQuery(){
        System.out.println("-----Get All Product Info----");
	    if (!isProductInfoFormInitialized) {
		    initProductInfoForm();
	    }

        productInfoForm.deleteAll();
	    

⌨️ 快捷键说明

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