Java 2 micro edition

504 113 0
Java 2 micro edition

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

WH_Java2.book Page i Monday, March 4, 2002 9:59 AM Java Micro Edition www.it-ebooks.info WH_Java2.book Page ii Monday, March 4, 2002 9:59 AM www.it-ebooks.info WH_Java2.book Page iii Monday, March 4, 2002 9:59 AM Java Micro Edition Java in Small Things JAMES WHITE DAVID HEMPHILL MANNING Greenwich (74° w long.) www.it-ebooks.info WH_Java2.book Page iv Monday, March 4, 2002 9:59 AM For online information and ordering of this and other Manning books, go to www.manning.com The publisher offers discounts on this book when ordered in quantity For more information, please contact: Special Sales Department Manning Publications Co 209 Bruce Park Avenue Greenwich, CT 06830 Fax: (203) 661-9018 email: orders@manning.com ©2002 by Manning Publications Co All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end Manning Publications Co 209 Bruce Park Avenue Greenwich, CT 06830 Copyeditor: Lois Patterson Typesetter: Martine Maguire-Weltecke Cover designer: Leslie Haimes ISBN 1-930110-33-2 Printed in the United States of America 10 – VHG – 06 05 04 03 02 www.it-ebooks.info WH_Java2.book Page v Monday, March 4, 2002 9:59 AM To my wife, Kelly J.W To my wife, Amy Votava and my daughter, Olivia Hemphill D.H www.it-ebooks.info WH_Java2.book Page vi Monday, March 4, 2002 9:59 AM www.it-ebooks.info WH_Java2.book Page vii Monday, March 4, 2002 9:59 AM contents preface xv acknowledgments xviii about this book xx about the cover illustration Part xxiii Developing with J2ME 1 Introduction 1.1 So what is J2ME anyway? Where is J2ME being applied? 1.2 What is a small device? The vast consumer space Consumer electronic and embedded devices 1.3 J2ME’s role in wireless and mobile applications Is J2ME mobile? ✦ Is J2ME wireless? Wireless vs mobile 1.4 The Java edition trilogy J2SE 10 ✦ J2EE 10 J2ME 11 ✦ Why we need J2ME 11 1.5 The case for Java 12 Is Java right for small devices? 12 ✦ Java’s beneficial features 13 1.6 Origins of J2ME 15 Java’s origins 15 ✦ The return of Java in small devices 16 1.7 The J2ME community 16 J2ME’s guiding light, the Java Community Process 16 1.8 J2ME products and alternatives 17 1.9 Summary 18 vii www.it-ebooks.info WH_Java2.book Page viii Monday, March 4, 2002 9:59 AM J2ME architecture 19 2.1 Goals of the J2ME architecture 19 Support for multiple devices 20 Support for device-specific functionality 20 Maintaining a common architecture 21 2.2 Accommodating opposing needs 21 Configurations and profiles 22 ✦ A high-level view of J2ME 23 2.3 Configurations: a closer look 24 Connected Limited Device Configuration (CLDC) 25 The Kilobyte Virtual Machine (KVM) 27 Connected Device Configuration (CDC) 28 C-Virtual Machine (CVM) 29 2.4 Profiles: a closer look 29 Two types of profiles 30 ✦ Profiles are modular 30 J2ME profiles extend J2ME configurations 31 2.5 Choosing a J2ME profile 31 Mobile Information Device Profile (MIDP) 32 PDA Profile (PDAP) 32 ✦ Foundation Profile 32 Personal Profile 32 ✦ RMI Profile 33 ✦ Personal Basis Profile 33 Multimedia Profile 33 ✦ Gaming Profile 34 Wireless Telephony Communications API (WTCA) 34 ✦ KJava 34 2.6 Write once, run anywhere issues 35 Varied device needs 35 ✦ J2ME architecture increases WORA 36 2.7 Runtime environment 36 2.8 Designing J2ME applications 36 2.9 Summary 38 Developing a J2ME application 39 3.1 Investment quote application requirements 40 The investment quote application customer 40 Requirements analysis 41 3.2 Designing the investment quote application 42 Application control 42 ✦ User interface design 43 Persistent storage 45 ✦ Networking and input/output 46 3.3 Developing J2ME applications 48 Obtaining the development environment 48 Creating the applications 49 ✦ Runtime environment 49 3.4 Investment quote application tour guide 50 3.5 Summary 51 viii C ONTENTS www.it-ebooks.info WH_Java2.book Page ix Monday, March 4, 2002 9:59 AM Part Developing for cellular phones and pagers 53 A simple MIDP application 55 4.1 Questions about the MIDP development environment 56 Can I this without an actual device? 56 What device I start with? 56 Do I have to use the command line tools? 56 The example: what are we going to do? 56 4.2 Developing MIDP applications 56 Getting started 57 ✦ What is a MIDlet? 58 Compiling the application 60 ✦ Preverifying the application 61 Running the application 61 ✦ Troubleshooting 62 JARing MIDlets 63 ✦ Developing MIDlet suites 64 Running MIDlet suites from a web server 67 Installing MIDlet suites locally 67 4.3 Summary 68 MIDP user interface 69 5.1 MIDP application control 70 5.2 The investment quote application control in MIDP 71 5.3 Two types of MIDP user interface and event handling 75 High-level API 76 ✦ Low-level API 76 5.4 The MIDP user interface API 77 MIDP display control 77 ✦ MIDP high-level user interface API 78 MIDP low-level user interface API 87 The investment quote application’s user interface in MIDP 91 5.5 Handling user interactions in MIDP 105 High-level event handling 107 ✦ Low-level event handling 110 Handling the events of the Investment Quote Application 114 5.6 MIDlets on other devices 130 5.7 Summary 133 MIDP data storage 134 6.1 JDBC parallel 135 6.2 Storage structure 136 Record store 136 ✦ Records in the record store 137 6.3 RMS API 138 Record store construction and access 138 ✦ Record store exceptions 141 Record store listener 142 ✦ Comparing records 144 Filtering records 145 ✦ Enumerating through records 146 ix CONTENTS www.it-ebooks.info WH_Java2.book Page x Monday, March 4, 2002 9:59 AM 6.4 Persistent storage in the investment quote application Defining the stock/mutual fund record 149 Storing quotes 150 ✦ Retrieving quotes 156 6.5 Summary 166 Connecting to the Internet 167 7.1 Micro edition package connectivity 168 Using the Connector class to open a channel 168 7.2 Similar but smaller I/O package 169 Streams 170 ✦ Readers/Writers 170 7.3 Implementing the Internet investment quote service Getting a quote service connection 172 Extracting the price quote from the HTML 177 The MIDlet’s handling of quote data 180 7.4 Summary 186 Part 149 171 Developing for PDAs 187 J2ME on a PDA, a KJava introduction 189 8.1 PDA profile alternatives 190 Java PDA development environments 190 What is KJava? 191 ✦ What is MIDP for Palm OS? 192 8.2 HiSmallWorld in KJava 192 Getting Started 192 ✦ What is a Spotlet? 193 Compiling HiSmallWorld 194 ✦ Preverifying KJava applications 197 Creating the Palm OS application 198 ✦ Running the application 202 8.3 Deploying to the actual device 211 8.4 HiSmallWorld revisited using MIDP for Palm OS 213 MIDP application code 214 ✦ Converting the JAR file to PRC 215 Deploying the MIDP for Palm OS applications 216 8.5 Summary 217 KJava user interface 218 9.1 KJava application control 219 9.2 The investment quote application control in KJava 220 9.3 KJava user interface 225 Drawing to the display with the graphics object 225 ✦ Components 231 Custom components 239 ✦ KJava collection classes 239 x C ONTENTS www.it-ebooks.info WH_Java2.book Page 466 Monday, March 4, 2002 9:59 AM Table D.1 The directory structure of the J2ME Wireless Toolkit that contains the necessary files and executables to run the toolkit as well as the applications you develop D.3 Directory Purpose \apps Directory containing the demo applications provided with the toolkit as well as the future home for applications you create \bin Batch and exe files of the J2ME Wireless Toolkit \docs The J2ME Wireless Toolkit documentation directory containing the Users Guide among other documents \lib The CLDC and MIDP API class files which are used during the compiling and preverifying of your applications \wtklib Emulator device property files HELLO WORLD PROJECT REVISITED In chapter 4, we created a simple Hello World MIDlet to demonstrate the MIDP technology and to get familiar with how to create MIDP applications We will reuse the code from chapter to demonstrate how to build an MIDP application using the J2ME Wireless Toolkit The HiSmallWorld MIDlet from chapter is listed below import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.*; public class HiSmallWorld extends MIDlet { private TextBox textbox; public HiSmallWorld() { textbox = new TextBox("", "Hi Small World!", 20, 0); } public void startApp() { Display.getDisplay(this).setCurrent(textbox); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } } D.3.1 466 Starting the toolkit The J2ME Wireless Toolkit provides for a host of tools to help you build your application The KToolBar is a graphically oriented user interface tool for accessing most of the tools provided in the toolkit After installing the J2ME Wireless Toolkit, the KToolBar should be a program listed in the Programs of your desktop (under version 1.0.3, you will find it under Start –> Programs –> J2ME Wireless Toolkit 1.0.3) Clicking A PP E N D I X D www.it-ebooks.info J2ME WIRELESS TOOLKIT WH_Java2.book Page 467 Monday, March 4, 2002 9:59 AM Figure D.2 The KToolBar allows developers to configure, compile, preverify, package, and test MIDP applications on KToolBar will start the application and you should see a window like that depicted in figure D.2 This application allows you to create and configure projects, build or package your applications and run your applications in various emulators Applications in this instance, as we shall see, mean MIDlet suites D.3.2 Creating a project Development in the KToolBar is accomplished via a project A project is a collection of MIDlets in a MIDlet suite Before writing, packaging or testing any code, the MIDlet code must be established as part of a project To create a new project, push the New Project… button on the top left hand corner of the KToolBar window A New Project window will display, requesting you to provide a Project Name and MIDlet Class Name (see figure D.3) Figure D.3 A new project name and associated first MIDlet are entered in this window that displays after pushing the New Project… button on the KToolBar Enter the name of your MIDlet suite in the Project Name field In the case of our Hello World example, we enter the name SmallWorldSuite In the MIDlet Class Name field enter the name of the first MIDlet you want to be part of the suite In this example, our first and only MIDlet will be the HiSmallWorld class Once you enter these names and press the Create Project button on this window, a Settings for project “SmallWorldSuite” should display as seen in figure D.4 These are the settings or attributes for our project, MIDlet suite and all the MIDlets in the suite We discuss these attributes in the next section so don’t hit either the OK or Cancel button quite yet HELLO WORLD PROJECT REVISITED 467 www.it-ebooks.info WH_Java2.book Page 468 Monday, March 4, 2002 9:59 AM Figure D.4 When creating a new project, settings for the project, MIDlet suite and associated MIDlets are provided in this window Once the OK button on this window is pushed, a new J2ME Wireless Toolkit project is created Pay particular attention to the text displayed in the main KToolBar window after a project is created Move, but not cancel the Settings window so that you can see the KToolBar window As in our example shown in figure D.5, the toolkit indicates the directories being used by your new project In particular, it tells you where to place your MIDlet application code and associated files We will need this information later so it is a good idea to take note of these directories now Figure D.5 Note the directories that the toolkit specifies for source code, resource and library files These will be used later on in the application development 468 A PP E N D I X D www.it-ebooks.info J2ME WIRELESS TOOLKIT WH_Java2.book Page 469 Monday, March 4, 2002 9:59 AM D.3.3 Editing the project settings The Settings for project “SmallWorldSuite” window acts as an editor for the attributes found in the MIDlet and MIDlet suite JAD and manifest files If you push the tabs at the top of this window, you will see the various attributes that can be set for the MIDlet suite or individual MIDlet For example, if you push on the MIDlets tab, you will see a table listing the MIDlets in our SmallWorldSuite (see figure D.6) Figure D.6 The MIDlets associated with the project and MIDlet suite are listed in the MIDlets tab on the Settings window In our particular case, we not yet have an icon for our HiSmallWorld MIDlet So let’s change this to indicate that the MIDlet has no icon Click on the only row in the table and push the Edit button In the window provided (see figure D.7), remove the SmallWorldSuite.png text that is in the Icon text field and press the OK button Once you have entered the settings to your liking and push the OK button, the appropriate files (JAD and manifest) are modified by KToolBar and the project is created After the project has been created, you can return to the project settings by pushing the Settings button on the KToolBar As can be seen by the Settings window, there are several attributes in the project Once you have had a chance to get your first MIDlet up and running with the J2ME Wireless Toolkit, we suggest you read the documentation on the tool and play with these attributes HELLO WORLD PROJECT REVISITED 469 www.it-ebooks.info WH_Java2.book Page 470 Monday, March 4, 2002 9:59 AM Figure D.7 This window allows you to change the attributes of each MIDlet in the MIDlet suite D.3.4 Entering the Java code The J2ME Wireless Toolkit does not come with a text editor Therefore, you will need to use your favorite editor to type in the HiSmallWorld class code from page 466 into a HiSmallWorld.java file Once you have entered the code into a text file, the KToolBar does tell you where to save the file Namely, if you recall from the project’s creation, the KToolBar informed us that Java source code for our project should be placed in a certain directory In our example, this directory was c:\J2MEWTK\apps\ SmallWorldSuite\src (see figure D.5) Each project in the J2ME Wireless Toolkit has its own directory, which is usually kept in the \apps subdirectory of the toolkit’s main directory If you peruse to the SmallWorldSuite directory under the \apps directory now, you will already see a directory structure that includes a \bin directory Likewise, the \bin directory contains the manifest and JAD files for our tutorial suite We will not have to edit these files directly since the KToolBar provides the Settings window which will allow us to set attributes via the tool D.3.5 Building a project With the project or MIDlet suite set up via the KToolBar and the Java code entered and saved to the appropriate directory, we are ready to compile, preverify, and jar our code This part of the project is called “building” the application In the J2ME Wireless Toolkit, compiling, preverifying, and jarring the application all occur with the push of a button (provided there are no bugs in your code) To build your MIDlet suite, push the Build button on the KToolBar If your application build is successful, you will see text displayed in the KToolBar panel that indicates “Build complete.” If there were errors in your code, this same window will display messages indicating problems You will then have to go back to your text editor and attempt to fix the code D.3.6 Running a project It is easy to compile, preverify and jar your application It is equally easy to run and test your MIDlet suite in an emulator In fact, with the J2ME Wireless Toolkit, you can test your application in a number of emulators Located just below the New Project… button on the KToolBar is a Device drop-down box Select this dropdown box and pick any one of a number of device emulators as shown in figure D.8 470 A PP E N D I X D www.it-ebooks.info J2ME WIRELESS TOOLKIT WH_Java2.book Page 471 Monday, March 4, 2002 9:59 AM Figure D.8 The default list of emulation devices offered in the J2ME Wireless Toolkit allows you to test your MIDlet suite on any number of devices More device emulators can be added to the J2ME Wireless Toolkit See the documentation on the J2ME Wireless Toolkit for how to add emulators Notice that even the Palm OS device is listed We will discuss Palm OS emulation a little later For now, pick any one of the various cell phone emulators listed in the drop-down With your favorite phone emulator selected from the Device list, push the Run button on the KToolBar If all goes well, an emulator window running your MIDlet suite containing the HiSmallWorld MIDlet should display as in figure D.9 You can close the emulator at any time, or start more emulators to simulate many HiSmallWorld MIDlets all running at one time This can be advantageous when you want to test your networking applications as disFigure D.9 cussed in chapter Remember, the The SmallWorldSuite’s HiSmallWorld MIDlet does not yet HiSmallWorld MIDlet running in the have any event handling capabilities— DefaultColorPhone you will need to see chapter for emulator that—so you must power off the emulator to close the MIDlet application D.3.7 Palm OS Emulator The J2ME Wireless Toolkit has been designed to allow for the addition of new emulators in the future In fact, the J2ME Wireless Toolkit is already prepared to interact with the Palm OS Emulator if it is available on your system HELLO WORLD PROJECT REVISITED 471 www.it-ebooks.info WH_Java2.book Page 472 Monday, March 4, 2002 9:59 AM Figure D.10 Attempting to run a MIDlet suite with the Palm OS as the selected emulation device results in the KToolBar requesting the location of your emulator If you attempt to run the SmallWorldSuite with the Palm OS Emulator selected as the emulation device, you will be requested by the KToolBar to provide the location of the POSE on your system (see figure D.10) If you supply the location of the POSE in this window, then your MIDP applications will run as though we had developed MIDP for Palm OS applications D.3.8 Operating from the command line The KToolBar provides a convenient graphical user interface to the tools offered by the J2ME Wireless Toolkit However, the J2ME Wireless Toolkit is really an assembly of tools for creating and testing J2ME MIDP applications These tools can be utilized from the command line as opposed to the KToolBar Instructions for running the various tools are available in the J2ME Wireless Toolkit documentation D.4 SUMMARY In this book, we have provided you with the ins and outs of MIDP application development There is a growing number of development tools and IDEs and various products on the market to assist you in developing MIDlets and MIDlet suites Because it is free and has the capabilities to be tied to other Java development products such as Forte by Sun Microsystems, the J2ME Wireless Toolkit is a popular development tool used by the J2ME community 472 A PP E N D I X D www.it-ebooks.info J2ME WIRELESS TOOLKIT WH_Java2IX.fm Page 473 Monday, March 4, 2002 10:53 AM index A Abstract Windowing Toolkit (AWT) 76, 431 Abstract Windows Toolkit (AWT) 225 Active Server Pages (ASP) 334 address 368 Alert 78, 84–85, 90, 96–98, 159, 243 and Command 129 setImage 84 setString 84 setTimeout 84–85 AlertType 84 alphanumeric entry 292 anchor point 88, 228 Apache web server 67 application control MIDP 70–71 application descriptor file 64–65, 469 (See also JAD) applications multiple 333 ArrayIndexOutOfBoundsException 140 ASP See Active Server Pages AWT 78, 248, 431 (See also Abstract Windows Tookit) B beamReceive 250 beamSend 250 bitmaps 228–229 -bootclasspath 195 Borland JBuilder 431 Bouncy Castle 322, 449 buffer 140, 170 Button 231, 252 byte array for persistent storage 45 Palm OS database 267–271 RMS 135, 137–138, 140–141, 144, 146, 149 tutorial application record 150, 154 ByteArrayInput/OutputStream 170 ByteArrayInputStream 380 ByteArrayOutputStream 379 CDATA 351 CDC 24, 28, 43, 325, 430, 440 devices Personal and Foundational Profiles 431 CDMA 304 CDPD 304 Cell Broadcast Service (CBS) 34 cellular phones 40kB memory 57 and J2ME 4, 12 C and MIDP 56, 69, 130, 192 emulator 82, 117, 470 C 12, 443 (See also midp.exe) C++ 13–14, 440, 443, 457, 459–460 keypad 111 C/C++ 17, 439 keypad operation 74 CAD 439 selection button 74, 83 callback 106–107, 112–113, 130, 143 text entry 75 (See also event handling) CGI See Common Gateway Interface Canvas 87, 99, 158 ChaiVM 435 and commands 109, 113 character getGameAction 112 encoding 323 getKeyCode 112 localization 323 getKeyName 111 ChartCanvas 99–105, 116, 118, hasPointerEvents 113 121, 123–124, 156 hasPointerMotionEvents 113 CheckBox 231, 249 hideNotify 113 Choice 90 low-level event handling Choice interface 83, 86 methods 112–113 ChoiceGroup 79–80, 83, 86, 92–93, low-level events 110 107 paint 89, 113 class file verification 26, 416 repaint 87 class loaders 25 serviceRepaints 87 classpath 49, 61, 63, 195–197, 211 showNotify 113 CLDC 24–25, 307, 322 CanvasDemo 89 class file verification 28 card acceptance device (CAD) 439 data types 149 Caret 231, 236 devices 7, 57, 69, 131 CBS 34 473 www.it-ebooks.info WH_Java2IX.fm Page 474 Monday, March 4, 2002 10:53 AM CLDC (continued) download 192 GCF 167, 171 in the tutorial application 42, 50 KJava API 191–192, 198, 429 MIDP for Palm OS 213 Palm Overlay 191 security issues 26 CLDCClasses 195 close 169 Cloudscape 445 collection classes 431 com.sun.kjava 189, 240 combination lock 304 Command 86, 107–108 and alerts 129 label 108 menu 108 priority 108, 117 type 108, 117 command mode 113 commandAction 110 CommandListener 108–109, 116, 121, 150, 152–153, 180 Common Gateway Interface (CGI) 334 Common Object Request Broker Architecture (CORBA) 460 Compaq iPaq 428, 431 Comparable 144 compare 144 compile 470 components setlocation method KJava 235 configurations 22, 24 Connected Device Configuration (CDC) 24, 28 Connected Limited Device Configuration (CLDC) 24–25, 461 Connection 171, 366 connection interfaces 168 ConnectionNotFoundException 168 connections datagrams 394 Connector 168–170, 175, 277, 367–368 connector openInputStream 175 consumer electronics 4, 6–7, 11, 15–17, 428, 430, 435 ContentConnection 366 Coordinated Universal Time (UTC) 324 CORBA 11, 460 Creator ID 264 CrEme 432 C-Virtual Machine (CVM) 24, 29 CVM 24, 29, 425 garbage collection 426 memory references 426 D data format of stored 318 performance 318 storage 318, 444 synchronization 312, 444 data exchange formats 306 Data Manager 263–265, 267 data synchronization 312 SyncML 445–446 Database 263, 265–268 addRecord 267, 271 boolean resDB 266 close 267, 271 create 266 deleteRecord 267 getNumberOfRecords 268 getRecord 267, 270 int cardNo 266 int creatorID 266 int typeID 266 isOpen 266 java.lang.String name 266 setRecord 267 small footprint 318 Datagram 168, 366 DatagramConnection 366 DataInput 380 DataInput/OutputStream 170 DataInputConnection 377 DataInputStream 169, 380 DataOutput 379 DataOutputStream 379 DateField 79–80, 82, 107 debugging 424 development scenario 294 Dialog 237, 243 dialogDismissed 237, 243 DialogOwner 237, 243 dialogDismissed 243 dirty write 312 Display 58, 77, 91, 97 getCurrent() 78 getDisplay 77 setCurrent 78, 85, 94, 129 display limitations MIDP 76 474 Displayable addCommand 109 and Alert 84–85, 129 and alert 97 and Canvas 87–90, 99 and Command 109, 116, 118 and Form 79–80 removeCommand 109 displayable objects 77–78 DNS 277 DnsImpl 277 Document Object Model (DOM) 350 Document Type Definition (DTD) 307, 347 doGet 335 DOM See Document Object Model domain name services (DNS) 277 doPost 335 drawChar 100 drawing modes Graphics 226 drawLine 101 drawString 100, 226 DTD See Document Type Definition E embedded devices 4, 6, 11, 16–17, 428, 430, 435 EmbeddedJava 6, 431, 434, 442 ENABLE_CLDC_PROTOCOLS 392 Encryption 449 entering text 303 Enterprise Edition (J2EE) part of Java edition trilogy Enterprise JavaBean 10 EnterpriseClient 341 EnterpriseServletExample.java 337 EntryForm 92–96, 114, 116–118, 121–122 error handling 26 esmertec 192, 204 Jbed 429 event delivery methods 113 event handling 45, 66 database 142–144 high-level 107–110 low-level 110–113 events 105 serialized 107, 110, 113 EXCLUSIVE 93 EXCLUSIVE choice 86 exitButton 252 Extensible Markup Language (XML) 47, 347 INDEX www.it-ebooks.info WH_Java2IX.fm Page 475 Monday, March 4, 2002 10:53 AM F file system 228 FilteredInputStream 169 finalization 26–27, 414 Flash Memory 319 Flat files 318 floating point 26, 268 floating-point numbers 101, 149, 172 focus 248 Font 90 getFont 91 footprint 3, 11–13, 57, 200, 429, 434, 440 Form 79, 90 events 107 formats fixed-position 311 name-value 310 FormDemo 81 Foundation Profile 32 G game actions 111–112 game applications 76, 87, 110, 133 Gaming Profile 34 garbage collection 421 CVM 426 Gauge 79–80, 107 GCF 171–172, 174, 276 Generic Connection Framework 50, 167–168, 263, 366 GET 335 getBytes 150 getEncoding 372 getFlashID() 220 getGraphics 194 getLength 372 getType 372 GMT 324 Graffiti 219, 232–233, 244, 292, 303 help 233 Graphics 87, 89–90, 100, 194, 225, 242, 246 clearScreen 225 copy modes 230 copyOffScreenRegion 230 copyRegion 230 drawBitmap 228–229 drawBorder 227 drawImage 89 drawLine 226 drawRectangle 226 drawString 88 eight 227 frame types 227 getGraphics 225 getWidth 227 no-draw zones 229 on screen vs off screen 225, 229–230 resetDrawRegion 230 setDrawRegion 229 setFont 91 graphics context 194 Green Project 456 Greener Grass Corporation 294 Greenwich Mean Time (GMT) 324 intent Java Technology Edition 433 internationalization 323, 422 Internet 13, 46, 67, 167–168, 171, 173–174, 264, 275, 304, 443, 446, 457 screen phones 442 IntVector 240 InvalidRecordIDException 142 iPaq 190 Item 80, 107 ItemStateListener 107, 114 itemStateChanged 107 ITU-T keypad 111 J H J2EE 46 handlePenDown 250 database 135 Handspring 191 part of trilogy 16, 18 HelpDisplay 238 J2ME high-level API 76, 78 alternatives 17, 429, 435 high-level event handling 106–107 architectural tools 325 HiSmallWorld 466 architecture 19, 21 horizontal constant 88 configurations 22 HotSync 204–205, 213, 219 development tools 451 HTML 47, 167–169, 171, 173, devices 4–6 175–178, 306, 443 extend corporate enterprise HTTP 46, 167–169, 173–174, 177, systems 277, 306, 334–335, 446, 449 history 456 HttpConnection 171 origins 4, 15, 460 hypertext markup language profiles 22, 31 (HTML) 167–169 resources 453 hypertext transfer protocol runtime environment 36, 415 (HTTP) 46, 167–169 security 322 user interface 298 I Wireless Toolkit 464–472 J2SE 43 IDE 14, 48, 191–192, 194, 211, database 46, 135, 144 443, 464 development environment 48, 195 IllegalArgumentException 111 I/O 169–170 IllegalStateException 80 part of trilogy 16, 18 Image 87, 89 user interface 76, 78 createImage 90 J9 190 getGraphics 87 J9 virtual machine 435–437 ImageItem 79–80, 86, 90 JAD 64, 66–67, 72, 95, 132, 216 immutable image 89 JAM 36, 422 in-device verification 417 JAR 49, 63, 66, 72 information appliance jar 470 Input Stream Reader Java 16 read 175 alternatives 442 InputConnection 366, 377 benefits 13–15 InputSource 359 editions 9–12 InputStream 170, 359, 377, 380 history 456 InputStreamReader 168, 170, programming language 175, 381 servlets 334 Integrated Development Environwrite once and run anywhere 48 ments (IDEs) 14, 48, 56 475 I N D EX www.it-ebooks.info WH_Java2IX.fm Page 476 Monday, March 4, 2002 10:53 AM Java 465 Java Micro Edition defined Java Standard Edition (J2SE) Java Standard Edition SDK development environment 465 Java API benefits 136 Java Application Manager (JAM) 36, 49–50, 65, 422 Java Card 6–7, 438–439 Java Code Compact (JCC) 423 Java Community Process (JCP) 4, 24, 430, 461 Java Database Connectivity (JDBC) 444–445 Java Debug Wire Protocol (JDWP) 424 Java Development Kit (JDK) 10 (See also SDK) Java editions 18, 190 database 135 Java Foundation Classes (JFC) (See also Swing) 76 Java Media Framework 33 Java Naming Directory Interface (JNDI) 460 Java Native Interface (JNI) 25, 439 Java platform 458 Java Platform Debugging Architecture (JPDA) 424 Java Runtime Environment (JRE) 10, 50, 61, 215 Java SDK 195 Java TV 442 Java Virtual Machine Specification 27 java.io 168–170, 172, 175 javac 60, 62, 195, 197, 211 JavaHQ 132 JavaOne 11, 189, 461 JavaPhone 442 JavaServer Pages (JSP) 334 javax.microedition.io 168, 172, 175–176 javax.microedition.lcdui 77, 91, 100, 107–108, 110, 231 javax.microedition.midlet 58 javax.microedition.rms 138, 150, 156 Jbed 429 compiling 195 default icons 200 file creation 196 linking 199 log 197, 199, 202 Micro Edition 192 POSE 207 project creation 195–197 properties file 195–197, 201–202 supported platforms 203 Jbed Micro Edition CLDC 429 Jbed Profile for MID 429 JCC 423 JCP 16, 24, 190, 461 JDBC 10, 135–136, 262 JDK 10, 430, 434–435, 458 JDWP 424 Jeode 431 Jini 434, 441 JMF 33 JNDI 460 JNI 25, 435 JPDA 424 JRE 10, 36, 50 JSP 334 JV-Lite2 431 K K virtual machine 461 introduced 16 MIDP 57 Kada Mobile Platform 432 Kaffe 433 kAWT 225, 448 Kbrowser 449 keyDown 251 Kilobyte Virtual Machine (KVM) 24, 27 KJava 34, 131 application control 193 collection classes 239 color 225 component event handling 249 component event handling helper 250 custom components 239 Database 263 defined 191 download 192–193 event handling 248–250 introduced 461 introduction 189 paint() method 237 screen layout 231 screen size 225 setLocation 235 user interface 225 476 KToolBar 466–472 KVM 24, 27, 415, 461 introduced 189 KJava 191–192, 194, 198 MIDP for Palm OS 213 kXML 353, 447 L Layout Manager 78 List 78, 83, 86, 240 listener interface 106 listeners 107 lists 302 locale 325 locking policies lease 314 optimistic 313 pessimistic 314 low-level API 76, 87 low-level event handling 106, 110 M main 220–221 mask character 84 matches 146 memory 319 references in the CVM 426 MERI 430 Metrowerks CodeWarrior 431, 444 Micro Edition (J2ME) 9–12 MIDlet Active state 70 cellular phone 130 compiling 60, 214 converting 215–216 defined 58 destroyApp(boolean unconditional) 59, 70, 77 Destroyed state 70 HiSmallWorld 58, 214–217, 466–471 JARing 63–64, 214 javax.microedition.midlet.MIDlet class 70 pager 130 pauseApp() 59, 70 Paused state 70 preverifying 61, 214 running 61–62 startApp() 58, 70, 77 troubleshooting 62–63 INDEX www.it-ebooks.info WH_Java2IX.fm Page 477 Monday, March 4, 2002 10:53 AM MIDlet suite 72, 138–140, 156, 192, 216 associated record store 136–137 converting to PRC 132 defined 64 installing 67–68 JARing 66–67 need for 72 MIDletStateChangeException 59, 71 MIDP 32, 62, 67, 462 color 88 display control 77 display limitations 64, 76 download 57 for Palm OS 131 preverify 61, 64, 73 screen layout 86 screen size 76, 101 midp 63 MIDP 1.0 334 support of datagrams 304 support of sockets 304 MIDP for Palm OS 189–190, 192, 213, 218 converter tool 215–216 MIDP.prc 215 mobile application 167 mobile application models 326 Cradle-Synchronized 326 Persistent Network-Aware 326 Standalone 326 Mobile devices 7–9 Mobile Information Device Profile (MIDP) 32 first profile 462 model event-based 348 tree-based 348 Mosaic 457 Motorola’s Embedded Reference Implementation (MERI) 430 MPLICIT choice 86 Multimedia Profile 33 multiple applications 333 MULTIPLE choice 86 Multipurpose Internet Mail Extension 67 multiselecting 303 multithreading 413, 421 N NanoXML 351, 447 network 304 O Oak 15, 456 ObtainQuote 41–42, 149 ObtainQuoteMIDlet 71, 116, 180 compile 73, 95 event listeners 119 JARing 73, 95 preverify 73, 95 run 73, 95 startApp() 92, 97 storing data 150–153 ObtainQuoteSpotlet 243 application control 220–224 handling key entry events 250–252 handling pen movement 255–261 handling pen taps 252–255 storing data 269–273 user interface 241–244 off-screen memory 89 open() 168 openDataInputStream 168, 369 openDataOutputStream 168, 369 openInputStream 168, 369 openOutputStream 168, 369 Oracle Lite 445 OutputConnection 366, 377 OutputStream 170, 377, 379 OutputStreamWriter 170, 379 P pagers and J2ME and MIDP 56, 69, 130, 192 paint 99 Palm 16, 189 Palm database file 198 Palm Desktop Software 211 install tool 204–205, 211–213 Palm OS application 215–216 (See also PRC) application databases 285–287 categories 208–210, 213 Data Manager 191 databases 263–265 Emulator 471 exit 241 Jbed 203 KJava on 131 market share 428 MIDP on 56, 131 PDA 50 PRC 132 record database 263–265 resource database 263 system keys 219 Palm Resource File multiple PRC 199 single PRC 199 Palm’s Alliance Program 203 PalmVx 320 parameter list 368 parser small-footprint 351 XML 348 parsing 308 PDA 305, 428 cradle 11, 204–205, 213 databases 262–263 development environments 190–192 Java development environment 12 mobile/wireless device 7–9 text entry 232 virtual keyboard 232 PDA Profile (PDAP) 32, 131, 190, 218, 429 PDB 213, 262 penDown 321 penMove 321 Personal Basis Profile 33 personal digital assistants (PDAs) 189 and J2ME Personal Jworks 433 Personal Profile 32, 442 PersonalJava 32, 190, 430–433, 442 for OS-9 432 physical buttons 108, 112 pixel coordinate systems 87–88, 225 Pointbase Micro 445 pointer 76, 106, 132 pointing device 113 portability 22 between other Java environments 321 between profiles 320 POSE database emulator 267 deploying applications 207 deploying to 216 parameters 207 ROM 202–207 settings 211 POST 335 PRC 213 application name 200–202 477 I N D EX www.it-ebooks.info WH_Java2IX.fm Page 478 Monday, March 4, 2002 10:53 AM PRC (continued) converter tool 131–132, 215 files 131 icons 200–202 Palm OS 49 PRC (Palm Resource File) 198–202 pressed 250 preverification 26, 416 preverify 28, 61–62, 198, 211, 470 (See also MIDP preverify) PrintStream 170, 380 priority 118 profiles 22, 29 choosing J2ME 31 Foundation 32 Gaming 34 MIDP 32 multimedia 33 PDAP 32 Personal 32 Personal Basis 33 portability 320 RMI 33 types 30 WTCA 34 project 467–471 record store 138 addRecord 140–141, 154 addRecordListener 142 closeRecordStore 139 date 137 deleteRecord 141 deleteRecordStore 140 enumerateRecords 146 enumerating 146–149 getRecord 140 lifecycle 139 listRecordStores 140 locking 137 openRecordStore 138 record listener 147 removeRecordListener 142 setRecord 141, 154 time stamp 137 version number 137 RecordComparator 144, 148 RecordEnumeration 146 hasNextElement 147 hasPreviousElement 147 nextRecord 147 nextRecordId 147 previousRecord 147 previousRecordId 147 Q RecordFilter 145, 148 recordId 137–138, 143 questionnaire 325 RecordListener 142 QuoteMIDletSuite 72 recordAdded 143 QuoteMIDletSuite.jad 132 recordChanged 143 QuoteService 46–48, 170, 172–174, recordDeleted 143 177, 261, 263, 275–277 RecordStoreException 141 RecordStoreFullException 142 R RecordStoreNotFoundException 142 RadioButton 231, 241, 249 RecordStoreNotOpenException 142 RadioButtonGroup 231 reflection 25 RadioGroup 241 Region (See also Graphics) RAM 319 region 229–230 RDBMS 134–135 register 248 Reader 170, 380 relational database management rebuild 148 systems (RDBMS) 134 record reset 148 defined 136, 264 RetrievePrice 42, 149, 157, 273 enumerator 138, 155 RetrieveQuote 41–42, 149 in a record store 137–138 RetrieveQuoteMIDlet 71, 116 record access 140–141 compile 73 record enumeration 145, 154–155, event listeners 120 157 JARing 73 record filter 145, 154–155, 157 preverify 73 Record Management System retrieving data 156–160 (RMS) 135–137 run 73 record sequencing 144 startApp() 92 record sorting 144 478 RetrieveQuoteSpotlet application control 224 handling key entry events 250–252 handling pen movement 255–261 handling pen taps 252–255 retrieving data 273–275 user interface 244 RMI Profile 33, 441 RMS 135–137, 167, 262, 270 ROM Transfer 205–206 ROM Transfer.prc 204 Runtime 236 S SavePrice 42, 149, 154, 269 SAX See Simple API for XML schema 307, 347 scheme 368 Screen 78 and Command 109 setTicker 85–86 screen size MIDP 76 scrolling 95, 106 ScrollOwner 238 ScrollTextBox 232, 241, 255 SDK 196, 430, 440, 458–459, 465 security 415, 417 J2ME 322 SelectScrollTextBox 232 service 335 servlets 334 setCommandListener 110 setCurrent 97 setScrollValue 238 setString 97 set-top boxes 5, 8, 430 SGML 307 short message service (SMS) 34 Simple API for XML (SAX) 307, 350 Slider 232 small devices Small footprint databases 318 Small footprint parsers 351 smart cards 5–6, 438 smart phones 442 SMS 34 socket 168 socket listener 384 Socket Security Layer 322 SocketFactory 277 socketMessage() 383 soft button 75, 97, 108–109, 117 INDEX www.it-ebooks.info WH_Java2IX.fm Page 479 Monday, March 4, 2002 10:53 AM Software Development Kit (SDK) 10, 459 (See also JDK) SONY 16, 191 Spotlet compiling 194 defined 193 deploying 207, 211–213 event handling 248 focus 193–194, 219 HiSmallWorld 194–195 keyDown 248, 255 main 193, 219 penDown 249, 252–253, 269, 272–273, 275 penMove 249, 252–253, 255 penUp 249, 252–253, 255 register 219 unknownEvent 249 unregister 219 SSL See Socket Security Layer stakeholders 292 Standard Edition (J2SE) part of Java edition trilogy Standard Generalized Markup Language (SGML) 307 startApp() 104 stream 168, 170 StreamConnection 366, 377 StreamConnectionNotifier 366, 377 StringBuffer 174–176 StringItem 79–80, 105 Sun Microsystems 4, 9, 16, 189, 430 Wireless Toolkit 56 surrogate architecture 441 Swing 78, 218, 225 synchronization 413–414 SyncML 317 data synchronization 445–446 System System.currentTimeMillis 137 System.gc 27 System.out.println 130 T text entry 303 TextBox 58, 78, 83, 216, 232, 246 TextField 79–80, 84, 92–93, 96, 107, 232, 236, 241, 249–250 killCaret 236 loseFocus 236 setFocus 236 Thread java.lang.Thread 236 ticker 85–86, 97–98 time zones 324 Timer 107 TinyXML 352, 448 tutorial application control 42–43 command navigator 118 input/output 46–48 KJava 50 MIDP 50 networking 46–48 persistent storage 45–46 requirements 41 user interface 43–45 U UltraLite 445 Unicode characters 137 Unicode encoding 111 Uniform Resource Identifier (URI) 169, 172 Unstructured Supplementary Service Data (USSD) 34 URL 67, 174, 178 user interface display 298 navigation 299 user input 302 USSD 34 UTC 324 V ValueSelector 233 vast consumer space vertical constant 88 VerticalScrollBar 238 paint 238 virtual keyboard 292 virtual machine 11, 14, 57, 61, 442 (See also KVM, Jbed, MIDP.prc) CDC 425 CLDC 415 Visual Age Micro Edition 190 Visual Basic 443–444 Visual C++ 444 VisualAge Micro Edition 435–437 W Waba 438 WAP 449 WAP/WML 443 weak references 26 web browser 457 web server 67 Windows CE 323, 431–432, 438 wireless 167, 173 Wireless Access Protocol Wireless Application Protocol 443 wireless architecture 305 wireless device 8–9 Wireless Markup Language 8, 443 Wireless Telephony Communications API (WTCA) 34 WML 447 WMLScript 443 WORA 13, 35 World Wide Web 15, 47, 167, 171, 443, 457 Write Once, Run Anywhere (WORA) 13, 35 Writer 170, 379 WTCA 34 X XML 11, 47, 171, 306, 347, 444, 446–448 document 347 document attributes 350 document elements 350 document entities 350 example 353 open standards 350 parser 348 XML parsers 447 XMLClient 359 XMLClient.java 359 XMLHandler.java 362 479 I N D EX www.it-ebooks.info WH_Java2IX.fm Page 480 Monday, March 4, 2002 10:53 AM www.it-ebooks.info ...WH _Java2 .book Page ii Monday, March 4, 20 02 9:59 AM www.it-ebooks.info WH _Java2 .book Page iii Monday, March 4, 20 02 9:59 AM Java Micro Edition Java in Small Things JAMES... Is J2ME mobile? ✦ Is J2ME wireless? Wireless vs mobile 1.4 The Java edition trilogy J2SE 10 ✦ J2EE 10 J2ME 11 ✦ Why we need J2ME 11 1.5 The case for Java 12 Is Java right for small devices? 12. .. application control in KJava 22 0 9.3 KJava user interface 22 5 Drawing to the display with the graphics object 22 5 ✦ Components 23 1 Custom components 23 9 ✦ KJava collection classes 23 9 x C ONTENTS www.it-ebooks.info

Ngày đăng: 27/03/2019, 16:46

Từ khóa liên quan

Mục lục

  • Java 2 Micro Edition

    • preface

    • contents

    • acknowledgments

    • about this book

    • about the cover illustration

    • Part 1 Developing with J2ME

    • 1 Introduction

      • 1.1 So what is J2ME anyway?

        • 1.1.1 Where is J2ME being applied?

        • 1.2 What is a small device?

          • 1.2.1 The vast consumer space

          • 1.2.2 Consumer electronic and embedded devices

          • 1.3 J2ME’s role in wireless and mobile applications

            • 1.3.1 Is J2ME mobile?

            • 1.3.2 Is J2ME wireless?

            • 1.3.3 Wireless vs. mobile

            • 1.4 The Java 2 edition trilogy

              • 1.4.1 J2SE

              • 1.4.2 J2EE

              • 1.4.3 J2ME

              • 1.4.4 Why we need J2ME

              • 1.5 The case for Java

                • 1.5.1 Is Java right for small devices?

                • 1.5.2 Java’s beneficial features

                • 1.6 Origins of J2ME

                  • 1.6.1 Java’s origins

                  • 1.6.2 The return of Java in small devices

Tài liệu cùng người dùng

Tài liệu liên quan