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

📄 mobile3d.java

📁 可在索爱K700C上运行的3D例程
💻 JAVA
字号:
/**
 * 
 * COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2004. 
 * 
 * The software is the copyrighted work of Sony Ericsson Mobile Communications AB. 
 * The use of the software is subject to the terms of the end-user license agreement which 
 * accompanies or is included with the software. The software is provided "as is" and Sony Ericsson 
 * specifically disclaim any warranty or condition whatsoever regarding merchantability or fitness for 
 * a specific purpose, title or non-infringement. No warranty of any kind is made in relation to the condition, 
 * suitability, availability, accuracy, reliability, merchantability and/or non-infringement of the software provided herein
 *
 */
package com.sonyericsson.javatest.mobile3d;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;

/**
 * Mobile3D: Demo benchmark MIDlet for devices with Mobile 3D Graphics API (JSR 184) support.
 * 
 * This MIDlet displays rotating 3D cube with texture using mobile 3D Graphics library. There is a
 * Frame Per Second (FPS counter) displayed in the corner of screen. Menu is displayed ater user
 * presses any key. Menu allows to view device statistics, run demo again or exit application.
 *  
 */
public class Mobile3D extends MIDlet {
    public static Mobile3D instance = null;

    private String averageFpsString;

    DemoBase displayable = null;

    private String stringExit = "Exit";

    public String stringAppName = "Mobile3D Demo";

    private String stringNotSupported = "This device does not support Mobile 3D Graphics API.";

    private String stringErrorLoading = "Error loading images.";

    private String stringClass3D = "javax.microedition.m3g.Graphics3D";

    private Image imageTexture;

    /**
     * Class for displaying alert messages.
     *  
     */
    public class AlertClass implements CommandListener {
        private Command exitCommand = new Command(stringExit, Command.EXIT, 1);

        public void commandAction(Command c, Displayable s) {
            if (c == exitCommand)
            {
                destroyApp(false);
                notifyDestroyed();
            }
        }

        /**
         * Display the alert
         * 
         * @param alertText
         *            test to be displayed
         */
        public void showAlert(String alertText) {
            Alert alert = new Alert(stringAppName);
            alert.setTimeout(Alert.FOREVER);
            alert.setString(alertText);
            alert.addCommand(exitCommand);
            alert.setCommandListener(this);
            Display.getDisplay(instance).setCurrent(alert);
        }
    }

    private boolean loadImages() {
        try
        {
            imageTexture = Image.createImage("/textures/sonyericsson64.png");
        } catch (Exception e)
        {
            AlertClass errMsg = new AlertClass();
            errMsg.showAlert(stringNotSupported);
            return false;
        }
        return true;
    }

    /**
     * @return Returns the instance.
     */
    public static Mobile3D getInstance() {
        return instance;
    }

    /**
     * Load the demo scene
     * 
     */
    public static void loadDemo() {

        Demo displayable = new Demo();
        Display.getDisplay(instance).setCurrent(displayable);
    }

    /**
     * Quit the MIDlet.
     */
    public static void quitApp() {
        instance.destroyApp(true);
        instance.notifyDestroyed();
        instance = null;
    }

    /**
     * Construct the midlet.
     */
    public Mobile3D() {
        instance = this;
    }

    /**
     * Handle destroying the MIDlet.
     */
    public void destroyApp(boolean unconditional) {

    }

    /**
     * @return Returns the averageFps.
     */
    public String getAverageFpsString() {
        return averageFpsString;
    }

    /**
     * Handle pausing the MIDlet.
     */
    public void pauseApp() {
    }

    /**
     * @param averageFps
     *            The averageFps to set.
     */
    public void setAverageFpsString(String averageFps) {
        this.averageFpsString = averageFps;
    }

    /**
     * Main method. Load demo or otherwise.
     */
    public void startApp() {
        if (!loadImages()) {
            return;
        }
        if (checkSystemCompatibility())
        {
            loadDemo();
        } else
        {
            AlertClass errMsg = new AlertClass();
            errMsg.showAlert(stringNotSupported);
        }

    }

    /**
     * Check if system supports Mobile 3D graphics API
     * 
     * Preferred (and only ?) method is to try to load class from package javax.microedition.m3g.
     * 
     * @return bool true if support is present
     */
    private boolean checkSystemCompatibility() {
        try
        {
            Class.forName(stringClass3D);
        } catch (Exception e)
        {
            return false;
        }
        return true;
    }

    /**
     * Return the texture image
     * @return Returns the imageTexture.
     */
    public Image getImageTexture() {
        return imageTexture;
    }

    /**
     * Return application name
     * @return Returns the stringAppName.
     */
    public String getStringAppName() {
        return stringAppName;
    }

    /**
     * Return the exit label string
     * @return Returns the stringExit.
     */
    public String getStringExit() {
        return stringExit;
    }
}

⌨️ 快捷键说明

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