RIM has developed it's own JVM or Java Virtual Machine
for J2ME includes development of its own Java Virtual
Machine which provides support for the Connected
Limited Device Configuration (CLDC) and
the Mobile
Information Device Profile (MIDP).
Additional BlackBerry APIs
BlackBerry devices are enhances with additional
BlackBerry-specific APIs. Developers can create
applications that have the BlackBerry-native look
and feel, with more sophisticated features than are
afforded using standard Java MIDlets.
At the price of loss of portability, the BlackBerry APIs
allow the creation of applications that tightly integrate
with the BlackBerry devices and features.
Comparing The Standard API and the
Blackberry API
Comparing the Standard API supplied with
J2ME
shows that the Blackberry augments support for CLDC
and MIDP with it's own set of libraries.
Check the link to the API and compare it
to the that of
of the WTK toolkit and this will be evident. Please note
you might have to check the various JSRs other than
MIDP to get a feel for all of what the WTK supports.
Link to the Blackberry Documentation
http://www.blackberry.com/developers/docs/4.5.0api/index.html
How is Blackberry Different Than J2ME
- Additional Blackberry APIs
The Blackberry, in addition to supporting many of the
Java Standard APIs including the CLDC and MIDP
have many RIM-specific libraries. While a Blackberry
will support a standard MIDlet,
Blackberry developers
will tend to write BlackBerry specifc applications using
RIM's APIs. RIM's UI APIs offer better control over the
devices features.
- Standard Deployment Model
Blackberry's use a consistent deployment model
across all devices and carriers.
To use a Blackberry API a fee is paid to obtain a
signing key which allows access to the API.
- Blackberry Specific Application Architecture
A Java
MIDlet, to run on a Blackberry has to go
through some translation to adapt
the MIDlet to
Blackberry's platform. The
Blackberry VM is for
instance, described as a 'Java-like'
VM that uses
bytecode specific to the Blackberry
device and
architecture. As an example, Java
class files are
transformed into COD files, using
the Blackberry
compiler.
//
class to cod
Similarities and Differences
As a general rule, CLDC, MIDP, and BlackBerry
APIs can be mixed. The exception is the APIs for
creating user interfaces. The javax.microedition.lcdui
and net.rim.device.api.ui packages should not be
mixed.
// UI oil and vinegar
RIM's UI More Like
Swing
Where the Java Microedition UI classes depart from
their Swing origins, RIMs UI components are more
like Java's Swing.
While you are advised not to mix the lcdui with the
Blackberry ui package, it is evident once you start
using them that they have many common features
such as the Graphics class.
Key Classes
- net.rim.system.Application
The Application class is used when there is no
need for a UI or user interaction.
- net.rim.system.UiApplication
The UiApplication class is the basis for an
application with a User Interface.
The
main( ) Method
Diehard Java fans have to like the fact that RIMlets
use a main( ) method as an entry point into the
application.
The
Screen and the pushScreen( ) Method
The RIMlet screen like MIDP's screen is not movable.
The developer sets screen with the pushScreen()
method.
The RIMlet Moniker
A Java application written for the Blackberry using
RIM APIs is not portable so is correctly not called a
MIDlet. Instead the moniker RIMlet has been adopted.
Options
The options are to develop standard MIDlets and port
them to the Blackberry or develop dedicated RIMlets.
Really a third option is to develop standard MIDlets on
the Blackberry IDE so that the porting is not necessary.
Keep the CLDC in Any Case
If the developer chooses to develop dedicated RIMlets
the CLDC model should be used as a base. The RIM
APIs can be used to offer the BlackBerry-native look
and feel while the option remains to use J2ME-standard
APIs in other areas of the applications.
RIM Has it's own Persistence Model
RIM has it's own persistence model or you can use
MIDP RMS. For networking with the Blackberry, the
General Networking framework is used.
Architecture
BlackBerry devices are carried by many wireless
carriers such as Telus and Nextel.
Connection
A Blackberry device is subscribed to a carrier's network,
from where it links RIM's Network Operating Center or
NOC. The Network Operating Center connects to all
RIM's carrier partners and to BlackBerry Enterprise
Servers which are deployed throughout the world.
BIS, Blackberry Internet Service
" BIS stands for Blackberry Internet Service. Basically, this
is
a service from your provider that lets you receive email
and access the
internet on personal Blackberries. BIS
differs from BES, or Blackberry
Enterprise Server, in that
BIS retrieves personal email whereas BES
retrieves
corporate email. Normally, BIS provides push email for
up to
10 non-corporate email accounts and some form
of internet data service,
whether that be a set MB limit, or
unlimited."
-
quote from Blackberry FAQ,
BES
The BlackBerry Enterprise
Server or BES is software
that supplies a gateway to corporate email services
such as Microsoft Exchange and Lotus Notes.
Wireless Gateway Architecture
// diagram adapted from 'Programming the
BlackBerry With
J2ME',
// Q. Mahmoud
Blackberry
|
+-> Wireless
Tower
|
+-> Corporate
Firewall
|
+-> Blackberry
Enterprise
Server
|
+-> Corporate
E-Mail Server
+-> HTTPS
Corporate Apps & Content Servers
//
the Blackberry Enterprise Server can be configured
to do
// additional services such as the
Mobile Data Service
BlackBerry
Application Models
Qusay Mahmoud describes the two applications models
that enable developers to program for the Blackberry in
different ways.
The browser-based model focuses on developing in a
standard markup language. The two most popular markup
languages are the Wireless Markup Language (WML) or
the compact Hypertext Markup Language (cHTML).
Common Markup Languages
- WML // Wireless Markup Language
- cHTML
// compact Hypertext Markup Language
This simplifies but also limits the client interfaces.
//
we look at WML next class
Custom Java applications allows the creation of
custom GUIs and navigation. The custom applications
can be downloaded so they may be used even if the
device is outside the wireless coverage area.
// we have
covered the later but have yet to use
// an example of the markup style of development
RIM's JDE
RIM's Java Developer Environment or JDE is an
IDE that supplies all the tools and APIs necessary
to create Blackberry Java applications.
JDE requires the Java 2 SDK to run. It comes with a
BlackBerry
simulator for testing, but it is recommended
to obtain an actual BlackBerry
device.
Cod Files
The RIM JDE compiles Java source code and packages
it as a .cod file. This is a proprietary Blackberry format.
Preverification
As with the standard microedition, the code is preverified
before packaging into .cod files.
Version
At the time of this writing, late 2008, the JDE is in
version 4.6.
Converting
MIDlets to Run on the BlackBerry
Standard MIDlets can run on the BlackBerry. The
.jad and .jar files must be converted to the .cod
format. This is done using the 'rapc' command found
in the bin of the JDE installation
The rapc Command
The rapc command is in the bin of the JDE installation.
Example
// from 'Programming the BlackBerry With
J2ME', Qusay H. Mahmoud
rapc import="c:\BlackBerryJDE3.6\lib\net_rim_api.jar"
codename=LoginMIDlet -midlet jad=LoginMIDlet.jad LoginMIDlet.jar
//
all on one line
Loading the MIDlet.cod file into the
BlackBerry
The resulting MIDlet.cod file may be loaded into the BlackBerry
over a USB cable from the computer.
The javaloader Command
The javaloader command is used to load the .cod file storing
the MIDlet into the BlackBerry.
Example
// from 'Programming the BlackBerry With
J2ME', Qusay H. Mahmoud
javaloader -usb load LoginMIDlet.cod
The javaloader command also deletes midlets.
Example
// from 'Programming the BlackBerry With
J2ME', Qusay H. Mahmoud
javaloader -usb erase -f LoginMIDlet.cod
RIM's own HelloWorld RIMlet
Following are some salient points to start our
analysis of RIM's approach to creating mobile
applications.
- Extension of UiApplication
First as mentioned earlier, we see the UiApplication
extension that provides a visually based client
environment. Also all the imports are RIMs own
imports.
- Follows the standalone model with a main( )
Once again it is comforting to see that the Java
standalone model is followed where a main( )
method is provided as an entry point and it is the
classic!
Example
public static void main(String[] args)
- Use of the pushScreen( ) Method
The pushScreen( ) method is used in place of the
setDisplay( ) method used in the standard Java
MIDP API.
We see a Screen component being extended to
supply a panel that can be added to the display.
This is a reminiscent of building with the standard
Java UI components.
Some features in MainScreen are similar to what
we are use to. The setTitle( ) method sets a title.
the add( ) method adds components to the container.
Also in the close out, an alert dialog is created with
the following statement.
Example
Dialog.alert("Goodbye!");
RIM's own HelloWorld RIMlet
/**
*
*
HelloWorld.java
* The
sentinal sample!
*
*
Copyright © 1998-2008 Research In Motion Ltd.
*
* Note:
For the sake of simplicity, this sample application may not leverage
*
resource bundles and resource strings. However, it is STRONGLY
recommended
* that
application developers make use of the localization features available
* within
the BlackBerry development platform to ensure a seamless application
*
experience across a variety of languages and geographies. For
more information
* on
localizing your application, please refer to the BlackBerry Java
Development
*
Environment Development Guide associated with this release.
*/
package com.rim.samples.device.helloworlddemo;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
/*
*
BlackBerry applications that provide a user interface must extend
*
UiApplication.
*/
class HelloWorldDemo extends UiApplication
{
/**
* Entry point for application.
*/
public static void main(String[] args)
{
// Create a new instance of the application.
HelloWorldDemo theApp = new
HelloWorldDemo();
// To make the
application enter the event thread and start processing
// messages, we invoke the
enterEventDispatcher() method.
theApp.enterEventDispatcher();
}
/**
* <p>The default constructor. Creates all of the RIM UI
components
* and pushes the application's root
screen onto the UI stack.
*/
private HelloWorldDemo()
{
// Push the main
screen instance onto the UI stack for rendering.
pushScreen(new
HelloWorldScreen());
}
}
/**
* Create
a new screen that extends MainScreen, which provides default
* standard behavior for
BlackBerry applications.
*/
/*package*/
final class HelloWorldScreen extends MainScreen
{
/**
* HelloWorldScreen constructor.
*/
HelloWorldScreen()
{
// Add a field to the title region of the screen. We use a simple
LabelField
// here. The ELLIPSIS option truncates the label text with "..." if the
text
// is too long for the space available.
LabelField title = new
LabelField
("Hello World Demo" ,
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
// Add a read only
text field (RichTextField) to the screen. The RichTextField
// is focusable by default. In this case we provide a style to
make the field
// non-focusable.
add(new RichTextField("Hello
World!" ,Field.NON_FOCUSABLE));
}
/**
* Display a dialog box to the user with "Goodbye!" when the application
* is closed.
*
* @see net.rim.device.api.ui.Screen#close()
*/
public void close()
{
// Display a
farewell message before closing application.
Dialog.alert("Goodbye!");
System.exit(0);
super.close();
}
}
Getting Started
with the JDE
First, to develop RIM application's the Research in
Motion JDE or Java Development Environment is
needed.
There is a fair bit of discussion regarding backwards
compatibility on the net regarding selecting the right
JDE to go with the same version of operating system.
For instance, I found version 4.6 a bit slow because
of all the stuff it loads. An earlier version perhaps 4.3
would be perhaps a little snappier place to start
developing Java applications.
Following is the location where the JDE can be
downloaded from.
RIM JDE Download Site
http://na.blackberry.com/eng/developers/javaappdev/javadevenv.jsp
To get started with the Research in Motion JDE, you first
must create a workspace. In the workspace subdirectories
for each project are added. Then source files are created,
the application is built and tested.
Following are the steps in summary.
Steps to creating a Java
application in RIM's JDE.
- Create a Workspace
- Create a Project
- Create a Source File
- Insert the File into the Project
- Build the Application
- Debug as is Necessary
Create a Workspace
1. From the File menu, choose 'New Workspace'.
Enter a name for the workspace and a
path for
the directory where the
workspace will be saved.
--> Press OK
2. Create a Project
From the Project menu, choose Create new
project. Enter a name for the project and a
directory where it should be saved
--> Press OK.
3. Create the Source Files
1. From the File menu, choose New --> Java File
Give a name to the file and directory
location
--> Press OK
3. Insert the File Into the Project
In the editor pane, right-click the file
Choose Insert into project.
4. Add Source Code
5. Select BuildAll and Run from the Build Tab.
Note
It takes JDE 4.5 and 4.6 a long while before the
Emulator is fully loaded.
Below is a sample from 'Programming the
BlackBerry With J2ME' by Qusay H. Mahmoud.
HelloApp Sample
//
from 'Programming the BlackBerry With J2ME'
// by Qusay H. Mahmoud.
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
public class HelloApp extends UiApplication {
public static void main(String argv[]) {
HelloApp app = new
HelloApp();
app.enterEventDispatcher();
}
public HelloApp() {
pushScreen(new
HelloScreen());
}
}
class HelloScreen extends MainScreen {
public HelloScreen() {
super();
LabelField title = new
LabelField
("BlackBerry App",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
add(new
RichTextField("Welcome to Developing BlackBerry Apps Tutorial"));
}
public boolean onClose() {
Dialog.alert("Visit Again!");
System.exit(0);
return true;
}
}
Invoking
the MIDlet Once the Emulator is Loaded in 4.6
Once the emulator is loaded you need to navigate
on it to find and start the MIDlet. Press the track
ball three times to get to the main screen. Press
the button to the left of the track ball (with the paw
print from a 7 toed animal). This takes you to
application. While you can grab the track ball
and hold down the left mouse button as you drag
around, it is easier just to use the roller on the
mouse to get to the icon of a folder with an arrow
pointing into it. That is the downloads folder. Click
it. Use the roller to find your MIDlet. Press the roller
button to start it.
JDE Version 6
With Version Six you just need to hit the Application
'Paw'. ( I see now the icon is imitating a 'thumb print'
of a screen with a bunch of icons on it.) Then scroll
through until you find your application.
Notice the application will be named to whatever you
called the project.
A Selective Survey of Blackberry API
Considering that much of the 'plumbing' can be done
with the MIDP profile, we can focus on the major
differences between the two platforms.
Recall the recommendation to use either one UI API
or the other, Java's or RIM's own. Since a great deal
of what can be enhanced when writing an application
for a RIM device is in using it's user interface API
when programming for the RIM device you will probably
want to use their API.
We survey it below.
The user interface package has a parent package
and five sub containers.
The Blackberry User Interface
Package and Sub-Packages
- net.rim.device.api.ui
- net.rim.device.api.ui.autotext
- net.rim.device.api.ui.component
- net.rim.device.api.ui.container
- net.rim.device.api.ui.decor
- net.rim.device.api.ui.text
The Color and Graphics Class
The Blackberry approach is to supply a load of color
constants. The documentation indicates these correspond
to those specified in HTML 4.0. Custom colors can
be obtained by specifying RGB as int values where
the byte value is stored in the int as follows.
Color Components Stored in
an int Value
| alpha | red
| green
|
blue |
// alpha does not seem to be supported
The Graphics class is very similar to that supported
in MIDP and works in the expected manner. Some
calls are shown below.
The
MIDlet may be made a little leaner
by wildcarding
the imports. We also use a minimum label and assume
we will use short strings in it.
Color Code Example
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
class ColorDemo extends UiApplication{
public static void
main(String[] args){
ColorDemo theApp
= new ColorDemo();
theApp.enterEventDispatcher();
}
private ColorDemo(){
pushScreen(new
ColorScreen());
}
}
final class ColorScreen extends MainScreen{
ColorScreen(){
LabelField title = new LabelField("Color
Demo");
setTitle(title);
add(new RichTextField("Color Demo!" ,Field.NON_FOCUSABLE));
}
public void paint(Graphics g)
{
g.setColor(Color.RED);
g.fillRoundRect(100,100,100,100,100,100);
g.drawText("RED INTEGER: " + Color.RED, 20,20);
g.setColor(Color.GREEN);
g.fillRoundRect(150,150,100,100,100,100);
g.drawText("GREEN INTEGER: " + Color.GREEN,20,40);
g.setColor(Color.BLUE);
g.fillRoundRect(50,150,100,100,100,100);
g.drawText("BLUE INTEGER: " + Color.BLUE,20,60);
//
have the API to give us a custom color
g.setColor(16761024);
g.fillRoundRect(200,200,100,100,100,100);
g.drawText("A LIGHT PINK",50,200);
g.setColor(65280);
g.fillRoundRect(250,200,100,100,100,100);
g.drawText("REAL GREEN",50,220);
}
//
Bye! Dialog
public void close(){
Dialog.alert("Bye!");
System.exit(0);
super.close();
}
}
The
Component
and Decor Packages
The component package has the Blackberry components.
They work in a predictable fashion. Following is an example
that shows a number of them in use.
The DateField Class
A plain Date object, created with an empty constructor
fixes the date to January, 1970. You need to instatiate
a Date object to get the current date.
Border and Background
The Blackberry API uses a Border and Background
factory for setting borders on fields and backgrounds.
Solid backgrounds of specified colors can be set
along with other sorts of backgrounds.
In the following example two backgrounds are set
and the editable text field also has it's border set.
The border method takes four int values each which
appears to specify the number of pixels that will be
used in the perspective field. The fields are listed in
the method clockwise, starting at the top, then right,
bottom and left.
Components and Decor Examples
import java.util.Date;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.decor.*;
class Pasta extends UiApplication{
public static void
main(String[] args){
Pasta p = new
Pasta();
p.enterEventDispatcher();
}
private Pasta(){
pushScreen(new
ComponentScreen());
}
}
final class ComponentScreen extends MainScreen{
ComponentScreen(){
LabelField title = new
LabelField("Cafeteria");
setTitle(title);
DateField datefield = new DateField();
datefield.setDate(new Date());
Background datebg
=BackgroundFactory.createSolidBackground(Color.CORNSILK);
datefield.setBackground(datebg);
add(datefield);
add(new CheckboxField("Beverage",false));
add(new CheckboxField("Salad",false));
add(new CheckboxField("Vegetable",false));
add(new CheckboxField("Main Course",false));
add(new CheckboxField("Potato",false));
add(new CheckboxField("Desert",false));
BasicEditField basic = new BasicEditField
("\nTIME: "," When can we expect you?");
Background bg =BackgroundFactory.createSolidBackground(Color.ALICEBLUE);
basic.setBackground(bg);
Border border =BorderFactory.createBevelBorder
(new
XYEdges(5,2,5,2));
basic.setBorder(border,true);
add
(basic);
add(new LabelField("\nThanks!"));
System.out.println(new XYEdges().top);
}
// See you soon! Dialog
public void close(){
Dialog.alert("See you
soon!");
System.exit(0);
super.close();
}
}
/*
* BlackBerryMapsDemo.java
*
* Copyright © 1998-2008 Research In Motion Ltd.
*
* Note: For the sake of simplicity, this sample application may
not leverage
* resource bundles and resource strings. However, it is
STRONGLY recommended
* that application developers make use of the localization
features available
* within the BlackBerry development platform to ensure a seamless
application
* experience across a variety of languages and geographies.
For more information
* on localizing your application, please refer to the BlackBerry
Java Development
* Environment Development Guide associated with this release.
*/
package com.rim.samples.device.blackberrymapsdemo;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
/**
* This sample features a main screen including menu items which
display respective
* screens highlighting specific aspects of the BlackBerry Maps
API's. Each of these
* screens offer menu items that will invoke the BlackBerry Maps
application in some
* manner. See the GPS and BlackBerry Maps Development Guide for
more information.
*/
class BlackBerryMapsDemo extends UiApplication
{
/**
* Entry point for the application.
*/
public static void main(String[] args)
{
BlackBerryMapsDemo app = new
BlackBerryMapsDemo();
app.enterEventDispatcher();
}
/**
* Constructor
*/
private BlackBerryMapsDemo()
{
BlackBerryMapsDemoScreen
screen = new BlackBerryMapsDemoScreen();
pushScreen(screen);
}
}
Micro
Support for Markup Languages
An interesting MIDlet comes as a demo for the Blackberry.
It is an example of Scalar Vector Graphics supported in a
markup language that is a dialect of XML.
Following is the example supplied for the Blackberry MIDlet
that comes with the Blackberry JDE.
Scalar Vector Example
// from the
Blackberry Samples
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
baseProfile="tiny" width="100%" height="100%">
<!--
Circle -->
<circle id="e1" cx="230" cy="140" r="50" fill="blue"
stroke="black" stroke-width="2"/>
<!--
Rectangle with rounded corners and transparency -->
<rect id="r1" x="50" y="60" width="180" height="80"
rx="4" ry="4" fill="red" fill-opacity="0.7" stroke="rgb(0,0,128)"
/>
<!-- Text with a system font -->
<text id="t1" x="100" y="100" font-family="BBAlpha
Sans" font-weight="bold" font-size="16">Hello World!</text>
</svg>
Below is the Java Code that goes with the XML script
noted above.
Analysis
Notice the general pattern is maintained, where a
custom screen holding most of the key functionality
is launched from inside a runner class with a main( )
method.
A
Regular Midlet!
This example is based on the regular MIDP libraries
we are familiar with from the course. There is though
an additional package that is knew, the m2g package.
More
Like Regular Java than the J2ME!
It really seems that the RIM developers were able to
implement a programming model more similar to
the J2SE than Java's own J2ME. This might be due
to the powerful microprocessor RIM developers can
expect to have in every Blackberry device.
Image
Loading
As an example notice the image loading below is
very similar to what is done in standard Java where
a createImage method is used to stream in an image
from file.
Example
// from SVGMidletDemo, Blackberry JDE
return (SVGImage)SVGImage.createImage(inputStream, null);
On the other hand there are some special method calls
on objects of the javax.microedition.m2g package which
would need to be tracked down.
SVGMidletDemo.java
Demo
// from the Blackberry JDE
/*
*
SVGMidletDemo.java
*
*
Copyright © 1998-2008 Research In Motion Ltd.
*
*
Note: For the sake of simplicity, this sample application may not
leverage
*
resource bundles and resource strings. However, it is STRONGLY
recommended
* that
application developers make use of the localization features available
*
within the BlackBerry development platform to ensure a seamless
application
*
experience across a variety of languages and geographies. For
more information
* on
localizing your application, please refer to the BlackBerry Java
Development
*
Environment Development Guide associated with this release.
*/
package com.rim.samples.device.svgmidletdemo;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.m2g.*;
import java.io.*;
/**
*
Simple demo midlet which uses JSR226 to load a
*
SVGImage and self render it using ScalableGraphics.
*/
public class SVGMidletDemo extends MIDlet
{
// The svg file
private static final String SVG_URL = "/sample.svg";
/**
* @see javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp()
{
try
{
SVGImage image =
loadSVGImage(SVG_URL);
Canvas canvas = new MySVGCanvas(image);
// Get the
display and set our canvas as the currently display
one.
Display display = Display.getDisplay(this);
display.setCurrent(canvas);
}
catch(IOException ex)
{
System.exit(1);
}
}
/**
* Loads an SVGImage from a given URL.
* @param url The path to the svg image we want to load.
* @return The loaded svg image.
*/
private SVGImage loadSVGImage(String url) throws
IOException
{
//
Open our input stream of the svg file we want to load.
InputStream inputStream = getClass().getResourceAsStream(url);
// Load our svg image from the input stream.
return
(SVGImage)SVGImage.createImage(inputStream, null);
}
/**
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp()
{
// Not
implemented.
}
/**
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean unconditional)
{
// Not implemented.
}
}
/**
*
Custom canvas used to render the svg image.
*/
class MySVGCanvas extends Canvas
{
private final int _canvasWidth = this.getWidth();
private final int _canvasHeight = this.getHeight();
private SVGImage _image;
private ScalableGraphics _sg;
/**
* Constructor.
* @param image The svg image we want to render in the canvas.
*/
MySVGCanvas(SVGImage image) throws IOException
{
_image = image;
_sg =
ScalableGraphics.createInstance( );
}
/**
* Paints the contents of the canvas using the ScalableGraphics
* rendering class and the SVGimage we want to render.
* @param g The graphics rendering context.
*/
public void paint(Graphics g)
{
if( _image == null )
{
return;
}
// Bind
target Graphics target to render to.
_sg.bindTarget(g);
//
Set our viewport dimensions.
_image.setViewportWidth(_canvasWidth);
_image.setViewportHeight(_canvasHeight);
//
Render the svg image (model) and x/y=0/0
_sg.render(0, 0,
_image);
// Release bindings on Graphics
_sg.releaseTarget();
}
}
Assignment
Modify any one of the MIDlets or RIMlets above to
whatever you wish. Then, in JDE 5 or 6, create your
own workspace, project and file. Screen shot the
JDE showing your workspace hierarchy and the
code. Also shoot the Blackberry emulation output.
Optionally
Create your own RIMlet from scratch and do the
same as above.