没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
Build your stock with J2ME
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Table of Contents
If you're viewing this document online, you can click any of the topics below to link directly to that section.
1. Introduction.............................................................. 2
2. Getting started .......................................................... 4
3. High-level user interface design ..................................... 6
4. Low-level user interface design...................................... 16
5. Record management system......................................... 22
6. J2ME networking....................................................... 28
7. Server-side design ..................................................... 35
8. Overcome J2ME limitations .......................................... 37
9. Wrap up.................................................................. 39
Build your stock with J2ME Page 1 of 40
Section 1. Introduction
J2ME tutorial overview
In this tutorial, we will build a typical Java 2 Platform, Micro Edition (J2ME) application, called
UniStocks, based on CLDC (Connected Limited Device Configuration) and MIDP (Mobile
Information Device Profile) APIs. As we build the application, we'll cover the following topics:
• MIDlet basics
• MIDP high-level user interface design
• MIDP low-level user interface design
• Record management system (RMS)
• J2ME networking and multithreading
• Server-side design
• Application optimization and deployment
• Overcoming J2ME limitations
About the author
Jackwind Li Guojie has been writing software professionally for many years. As leader
of the Jackwind Group, he provides software consulting and training servies in the
Asia-Pacific area. Currently, he is also pursuing research on soft computing at
Nanyang Technological Unversity, Singapore. You can contact Jackwind at
jackliguojie@hotmail.com.
About UniStocks
UniStocks is a stock application that enables the user to access and manage information of
any stock -- anywhere, anytime.
Like any stock application on your PC or on the Web, UniStocks lets the user:
• Add stocks (store stock symbols on a phone)
• Delete stock(s) (remove stock symbols)
• View live information of selected stocks, such as current high price, low price, volume, etc.
• View charts of historical data (one month, three months, six months, one year), price,
volume, and so forth.
UniStocks is based on a client-server architecture. The server will provide all required stock
information, such as live data and historical data.
Figures 1 through 3 show the main menu; the downloading status, and the stock historical
ibm.com/developerWorks
Presented by developerWorks, your source for great tutorials
Page 2 of 40 Build your stock with J2ME
chart, respectively.
Figure 1: UniStocks main menu
Figure 2: UniStocks download status
Figure 3: UniStocks historical chart
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Build your stock with J2ME Page 3 of 40
Section 2. Getting started
Choose your development tools
Few IDE tools are available for J2ME. You should already be familiar with the J2ME Wireless
Toolkit (WTK). WTK lets you compile, package, deploy, and execute J2ME applications.
WTK is not a real IDE, because it lacks important features like editing and debugging.
However, it is easy to use, which is appealing to many developers.
Other tools, such as IBM VisualAge Micro Edition and Borland JBuilder Mobile Set 2.0, are
extensions of mature IDEs. They provide wizards and other tools to help you create J2ME
applications.
You should choose the right tools according to your needs. (See Resources on page 39 for
IDE links.) For this project, we'll use the text editor Emacs with WTK 1.04.
Code the MIDlet
The J2ME platform consists of a set of layers, on top of which lies MIDP. We develop J2ME
applications on top of MIDP; thus, the applications are called MIDlets. Every J2ME
application must extend the MIDlet class so the application management software can
control it.
Here is a blueprint of our MIDlet:
public class UniStock extends MIDlet implements CommandListener
{
Display display;
private List menu;
private Command commandSelect;
private Command commandExit;
...
public UniStock() { // The constructor.
...
// Data initialization.
// Read saved data from RMS.
// Create UI components and the first screen (menu).
}
public void startApp() { // Enter the active state.
// Display the first screen.
display.setCurrent(menu);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
...
// Clean up data streams, network, etc.
...
ibm.com/developerWorks
Presented by developerWorks, your source for great tutorials
Page 4 of 40 Build your stock with J2ME
}
public void commandAction(Command c, Displayable s) {
notifyDestroyed();
}
// Other customized methods.
...
}
When the application management software invokes the startApp(), pauseApp(), or
destroyApp() method, the MIDlet's state changes. For example, when pauseApp() is
invoked, the MIDlet changes from an active to a paused state.
Because those methods signal state changes, they need to be lightweight in order to return
quickly. As you can see in the above code listing, we put most of the initialization process in
<init> and the constructor, rather than in startApp().
Warning: During application execution, startApp() and/or pauseApp() might be called
several times as the state changes. You should be careful never to place any initialization
code inside those two methods.
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Build your stock with J2ME Page 5 of 40
剩余39页未读,继续阅读
系统信息
- 粉丝: 2403
- 资源: 43
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论3