动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Java教程 ]的信息

本月文章推荐
.关于Hibernate开发框架中的各个包.
.提高J2EE层与数据库层交互操作能.
.全程解析Struts中两个相似类的解.
.Java中与注释有关的语法.
.开发实体EJB 增强的性能和开发.
.Apusic应用服务器的性能调节_JVM.
.布尔逻辑运算符.
.Java语言深入:对java.lang的研究.
.嵌入式Java的应用实例.
.回眸:Java改变了什么?.
.开始你的第一个struts应用程序.
.开发框架-Struts里过滤器的简单使.
.VisualCafe的主要工具介绍.
.new 运算符.
.Java开发工具与开发环境问答集.
.包版本标识.
.基于Java IDL的分布式程序设计.
.EJB系列教程之一.
.Java中类似于C语言中Sizeof功能实.
.java中的对象引用问题的再次理解.

The Xlet Application Model

发表日期:2008-1-5 |



  by Eric Giguere

In addition to supporting traditional Java[tm] applications, the Personal Basis Profile (PBP) also supports the Xlet application model. Derived from the Java TV APIs, Xlets are applications whose lifecycle is closely controlled and monitored by the system. They are very similar to the MIDlets defined by the Mobile Information Device Profile. Xlets are also supported by the Personal Profile, which is a superset of the PBP.

An Xlet application's entry point is always a class that has a public no-argument constrUCtor, and that implements the Xlet interface:

package javax.microedition.xlet;

public interface Xlet {
void destroyXlet( boolean unconditional )
throws XletStateChangeException;
void initXlet( XletContext context )
throws XletStateChangeException;
void pauseXlet();
void startXlet()
throws XletStateChangeException;
}

Along with the Xlet interface, the new javax.microedition.xlet package also defines an XletContext interface and two classes, XletStateChangeException and UnavailableContainerException. I'll discuss these shortly.

The timing of an Xlet's creation is up to the application management software on the device. When it's first instantiated, the Xlet's no-argument constructor is invoked. The constructor is often empty because no information on the Xlet's context is yet available. After instantiating the Xlet, the system invokes its initXlet() method, which does most of the the Xlet's initialization.

The single argument passed to initXlet) is an object that implements the XletContext interface. The Xlet customarily stores a reference to this object because the methods it eXPoses allow the Xlet to communicate with the system, in order to effect state changes and to Access its environment:

public class MyXlet implements Xlet {
XletContext context;

public void initXlet( XletContext context )
throws XletStateChangeException {
this.context = context;
// do initialization here
}

// other methods
}

If the Xlet can't initialize itself successfully, it must throw an XletStateChangeException to notify the system, which will destroy it and remove it from the list of active applications. The initXlet() method is where you'll usually create the application's initial user interface, using the subset of AWT (or a toolkit based on it) supported by the profile.

Once the Xlet has returned from the initXlet() method, the system invokes the startXlet() method, although not necessarily immediately. The startXlet method tells the Xlet that it's entering the active state and that it can display its user interface and open the system resources it needs. If the Xlet is not ready to enter the active state, it can refuse the transition by throwing an XletStateChangeException. The system will then return the Xlet to a paused state and attempt to reactivate it later.

Once the Xlet is in the active state, the system can pause it at any time. When the system needs to pause the Xlet, it invokes the Xlet's pauseXlet() method. The Xlet is then no longer active, so it should release as many system resources as it can, to make them available to other applications. On return from pauseXlet() the Xlet enters the paused state. The Xlet is not suspended, however, and any background threads it started continue to run.

The system terminates the Xlet by invoking its destroyXlet() method. If the boolean argument to destroyXlet() is true, the termination is unconditional: the Xlet is destroyed without any choice in the matter. If the argument is false, the Xlet can refuse termination by throwing an XletStateChangeException.

Usually, the system handles Xlet state transitions. As with MIDlets, however, Xlets have ways to request state transitions explicitly. They can invoke methods of the XletContext interface:

package javax.microedition.xlet;

import java.awt.Container;

public interface XletContext {
String ARGS = new String();

Container getContainer() throws
UnavailableContainerException;
Object getXletProperty( String key );
void notifyDestroyed();
void notifyPaused();
void resumeRequest();
}

An Xlet can pause or terminate itself at any point by calling the notifyPaused() or notifyDestroyed() method, respectively. The Xlet immediately transitions to the desired state. Note that the Xlet is the one initiating the state transition, and neither pauseXlet() nor destroyXlet() is called, so the Xlet should perform the appropriate cleanup before calling notifyPaused() or notifyDestroyed().

An Xlet in the paused state can request activation by calling the resumeRequest() method. Note that immediate activation is not guaranteed: the system controls activation and may deny the request. When it approves activation, it invokes the Xlet's startXlet() method.

The remaining methods of the XletContext interface are used to retrieve properties, typically during Xlet initialization.

The getContainer() method returns the Xlet's root container -- the instance of java.awt.Container that the Xlet uses as its primary AWT component. The root container is either an instance of java.awt.Frame or a container whose ultimate parent is such an instance.

The getXletProperty() method returns application-specific properties. The PBP specification does not define what these properties are or how they are associated with the application, except the special value XletContext.ARGS, which is used to oBTain the command-line arguments used to start the application.

In a traditional Java application you access the command-line arguments through the parameter passed to the main() method:

public static void main( String[] args ){
.....
}

In the Xlet model you get the arguments by calling getXletProperty() from initXlet():

public void initXlet( XletContext context ){
String[] args = (String[])
context.getXletProperty( XletContext.ARGS );
.....
}

I'll end this discussion of the Xlet model by providing a simple Xlet that displays a message, then waits for the user to press a key before terminating itself. You can use this as a template for your own Xlets.

import java.awt.*;
import java.awt.event.*;
import javax.microedition.xlet.*;

/**
* A basic Xlet that puts up a single component and
* waits for a keypress to terminate it. Use as
* the basis for your own Xlets.
*/

public class BasicXlet implements Xlet {
private XletContext context;
private Container rootContainer;
private Frame rootFrame;
private SimpleTextLabel label;

// Defer most initialization to the
// initXlet method

public BasicXlet(){
}

// Called by the system to notify you that the
// Xlet is about to be destroyed.

public void destroyXlet( boolean unconditional )
throws XletStateChangeException {
exit();
}

// Called by the Xlet to terminate itself.

public void exit(){
rootContainer.setVisible( false );
context.notifyDestroyed();
}

// Returns the XletContext

public XletContext getContext(){
return context;
}

// Returns the root container

public Container getRootContainer(){
return rootContainer;
}

// Returns the root frame. The spec guarantees
// that the root container is either a frame or
// has a frame as an ancestor.

public Frame getRootFrame(){
return rootFrame;
}

// Obtains and stores the root UI components.

private void initUI() throws
XletStateChangeException {
// Store the root container and traverse
// the containment hierarchy to find the
// container's frame

try {
rootContainer = context.getContainer();

Container tmp = rootContainer;
while( !( tmp instanceof Frame ) ){
tmp = tmp.getParent();
}

rootFrame = (Frame) tmp;
}
catch( UnavailableContainerException e ){
// If we can't get the root container,
// abort the initialization
throw new XletStateChangeException(
"XletInitialization aborted --
no container: "
+ e.getMessage() );
}
catch( NullPointerException e ){
// This should never happen, but....
throw new XletStateChangeException(
"XletInitialization aborted --
no frame: "
+ e.getMessage() );
}
}

// Called by the system to initialize the Xlet.

public void initXlet( XletContext context )
throws XletStateChangeException {
this.context = context;
// store the context for later use
initUI();

// Now build our user interface

label = new SimpleTextLabel( "Press a key
to exit" );
label.setBackground( Color.blue );
label.setForeground( Color.yellow );
label.addKeyListener( new KeyAdapter(){
public void keyTyped( KeyEvent e ){
exit();
}
} );

rootContainer.add( label );

// Don't make the container visible here in
// case it's a frame, defer it until the
// startXlet method is called.
}

// Called by the system to pause the Xlet.
// This is where you release any system resources
// you are using. The system is likely to make
// the root frame invisible, so there's no reason
// to make the container invisible.

public void pauseXlet(){
}

// Called by the system to activate the Xlet.

public void startXlet() throws
XletStateChangeException {

// Make sure the container is visible

if( !rootContainer.isVisible() ){
rootContainer.setVisible( true );
}
}
}
上一篇:to_stream函数让解析字符串更简单 人气:979
下一篇:TSP递归程序的优化 人气:665
浏览全部Java的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-10-12 team论坛 v2.0.4 bulid 080916 A
2008-10-12 Roclog v3.1.6
2008-10-12 SupeV v1.0.1 简体中文 GBK
2008-10-12 NetCMS v1.6.0.1010 正式版
2008-10-12 PHP考试系统PPFrame v1.2.7
2008-10-12 LPAS个人相册 v1.6.3
2008-10-12 快问仿百度知道系统 动态-静态-互
2008-10-12 方卡广告防点击系统 V1.0 GB2312
2008-10-12 泡菜内容管理系统[PCMS] v1.0 Bu
2008-10-11 联系人分组工具 v1.1 中文破解版
2008-10-11 FaceMelter变脸 v2.0 汉化破解版
2008-10-11 PathTracker道路跟踪仪 v1.2 破解
2008-10-11 Rooms手机聊天室 v0.6.7 破解版
2008-10-11 RemoteDesktop远程桌面 v1.0 破解
2008-10-11 ProRemote远程调音台 v1.0.1 破解
2008-10-11 PicShare照片共享 v1.0.0 破解版
2008-10-11 Photogene照片编辑器 v1.5 汉化破
2008-10-11 WriteRoom共享文档 v1.0 破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | js/vbs加密 | md5加密 | 进制转换 | UTF-8 转换工具 | Html转换js | Html转换asp | Html转换php | Html转换perl
实用工具:汉字翻译拼音 | 拼音字典 | 符号对照表 | 个税计算 | 实时汇率查询换算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 | 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵
SEO対策 中国語教室 ホームページ作成