otamidlet.java.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 118 行
SVN-BASE
118 行
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.midp.lib;import javax.microedition.lcdui.Alert;import javax.microedition.lcdui.AlertType;import javax.microedition.lcdui.Display;import javax.microedition.midlet.MIDlet;import javax.microedition.midlet.MIDletStateChangeException;/** * A base MIDlet class providing common functionality for various * MIDlets that participate in the OTA testing. * <p> * Typically, subclasses should override the {@link #go()} method, * providing custom behavior. * <p> * The default sequence of the execution is: {@link #sayHi()}, * {@link #go()} and then {@link #sayBye()} , all executed in the * thread, created during this MIDlet startup. */public abstract class OTAMIDlet extends MIDlet implements Runnable { protected String name = null; protected String running_string= null; protected String done_string = null; protected int bye_timeout = 1500; protected Alert al1 = null; private Thread t = null; public void run() { try { sayHi(); go(); } catch (Throwable t) { t.printStackTrace(); alert("Unexpected Throwable from the test: "+t); } finally { sayBye(); notifyDestroyed(); } } protected abstract void go(); protected void sayHi() { alert(Alert.FOREVER, running_string, 1000); } protected void sayBye() { alert(done_string); } protected void alert(String mess) { alert(bye_timeout, mess, bye_timeout); } protected void alert( int alert_timeout, String mess, int wait_timeout) { al1.setTimeout(alert_timeout); al1.setString(mess); Display.getDisplay(this).setCurrent(al1); long now = System.currentTimeMillis(); long end = now + wait_timeout; while (now < end) { synchronized (al1) { try { al1.wait(end - now); now = System.currentTimeMillis(); } catch (InterruptedException ie) {} } } } protected void startApp() throws MIDletStateChangeException { name = getAppProperty("MIDlet-Name"); running_string = "Running MIDlet: "+name; done_string = "Done MIDlet: "+name; al1 = new Alert(name, name, null, AlertType.CONFIRMATION); if (t == null) { t = new Thread(this); t.start(); } } protected void pauseApp() {} protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {}}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?