DirectorySoftwareBlog Details for "Don's Mobile Blog"

Don's Mobile Blog

Don's Mobile Blog
A collection of Java ME programming tutorials and articiles, and free cell phone games written by an independent Java developer.

Articles

Some Simple Text Effects in Java ME
2008-01-12 19:26:00
The Graphics.drawString() method in MIDP is pretty limited. You can specify a position, anchor point, and with the help of Graphics.setColor() and Graphics.setFont(), a color and a font, but that’s about it. However, its possible to do some simple text effects that are a bit more interesting by combining multiple calls to drawString(). First, lets take a quick look at the APIs involved. The drawString() method is pretty straightforward: public void drawString(String str, int x, int y, int anchor); The purposes of the str, x, and y parameters should be obvious. The anchor parameter defines how the text should be positioned in relation to the specified x and y coordinates. The accepted values are LEFT, HCENTER, RIGHT for the horizontal positioning, and TOP, BASELINE, and BOTTOM for the vertical positioning. These constants can be combined using the logical OR operator, e.g.: g.drawString("Hello World", 100, 100,   Graphics.TOP | Graphics.HCENTER); For ...
More About: Java , Text , Simple , Effects
Filtering and Ordering Records with RMS
2007-10-13 17:21:00
If you’ve ever used the Record Management System mechanism in MIDP, you already know how useful the RecordStore class can be for storing persistent data. In a previous tutorial, Using RMS to Store Persistent Data, we used the RecordStore.getRecord(int) method to retrieve a record by its ID. However, sometimes you may have more complex retrieval criteria than simply the record ID. That’s where the enumerateRecords () method comes in handy. In this article we will discuss how to filter and order a subset of records in a RecordStore object using enumerateRecords() The complete signature of the enumerateRecords() method looks like this: public RecordEnumeration enumerateRecords( RecordFilter, RecordComparator, boolean) throws RecordStoreNotOpenException This method returns an object that enumerates a set of records from the RecordStore. The RecordFilter argument allows the application to specify criteria that will used to return a subset of records. Similarly, the Reco...
More About: Erin , Cord
Using the Mobile Media API to Play Video
2007-08-13 13:36:00
The Mobile Media API (JSR-135) specification enables advanced audio and video support on Java ME devices. While MIDP 2.0 supports a subset of the MMAPI, this subset does not include the video or graphics components of the specification. In this article, we will look at a simple example of how to play video on a MMAPI enabled device. From a developer perspective, there are three major components you will need to worry about when working with the MMAPI. Play er objects are used to process content and rendered it to the user. Manager objects are factories that create Player objects. Lastly, you will need an object to provide the input for the content itself. This can either be a DataSource or an InputStream object. I’ve contructed a very simple MIDlet that demonstrates how to play a video, which I will be referring to below. The full source code for this MIDlet can be found here: MMAPI Video Demo Source Code. An example MPEG file is included in this file. If you are using...
More About: Bile
Text Messaging and the Wireless Messaging API
2007-07-16 15:42:00
Short Mess age Service (SMS), commonly referred to as Text Messaging, allows cell phone users to send short, plain-text messages to each other. The Wireless Messaging API (WMA) is an optional Java ME package that provides programmatic support for messaging technologies such as SMS. In this article we will look at how to use WMA to send SMS messages. The Wireless Messaging API can be found in the javax.wireless.messaging package. Sending of messages is handled by the MessageConnection class. MessageConnection objects are obtained by calling the open() method of the javax.microedition.io.Connector class with a URL string in the format: protocol://address:port For example: sms://+12125551212:5000 For SMS, the address part represents the MSISDN of the destination; typically this is a telephone number with country code. The port number is application specific. If you want the default messaging application of the destination device to open the message, simply leave off the port numbe...
More About: Text Messaging
Using MIDP Localization to Support Multiple Languages
2007-06-04 14:05:00
In today’s global economy, it is now more important than ever for software to be written with localization in mind, and mobile applications are no exception. Thankfully, NetBeans Mobility Pack makes the task easier with built-in support for MIDP localization. In this article we will take a look at MIDP localization, and how NetBeans helps us implement localized applications. A localized application has the ability to display text for the correct language based on the locale of the device. This includes text for labels, alerts, commands, buttons, etc. A localized application should be able to support new languages without making modifications to the application logic. In Java ME, this is achieved through MIDP localization. The current locale of the device can be determined by querying the microedition.locale system property. For example: String curLoca le = System.getProperty("microedition.loc ale"); The locale string contains an ISO standard language code and c...
More About: Languages , Support , Ages
Asynchronous Processing in Java ME: The Push Registry
2007-05-14 21:51:00
When writing mobile applications, you may encounter situations where you need to execute logic independently of user interaction. For example, your application may need to do something in response to an outside event, such as an e-mail message being received. You could put a loop in your application that periodically checks to see if the conditions for performing the task have been met. However, even if it were supported by the device, this approach could consume valuable resources. A better solution is to use the push registry API, which was added in MIDP 2.0. In this article we will take a look at the features and limitations of the push registry. The push registry allows your application to request that the device launch a MIDlet asynchronously. This ability can be incredibly useful for many types integration. There are two types of push events: push connections and push alarms. A push connection is triggered in response to an inbound network connection. A push alarm, on...
More About: Registry , Java , Sing , Proc , Sync
Working with the TiledLayer Class
2007-05-07 04:58:00
A common technique used in video games is to have a large scrolling background formed by a grid of smaller, reusable images. In MIDP 1.0, such a feature would need to be implemented from scratch or with a third-party library. However, MIDP 2.0 provides the convenient TiledLayer class to address this specific need. In this article we will look at a simple example of how to use the TiledLayer class in a Java ME application. TiledLayer is part of the javax.microedition.lcdui.game package that was introduced with MIDP 2.0. The constructor for the TiledLayer class accepts five parameters: the number of columns and rows in the grid, an Image object containing the tiles, and the width and height in pixels of each tile. TiledLayer(int columns, int rows, Image image, int tileWidth, int tileHeight) The image can have multiple rows of tiles. The tileWidth and tileHeight properties are used to break up the image into individual tiles. The tiles are numbered starting with 1 and incrementin...
More About: King , Class , Working , Workin
Using Preprocessor Directives to Port Java ME Applications
2007-04-01 23:42:00
There may be times when you want to take advantage of device-specific features, yet support as wide a selection of devices as possible. For example, perhaps you want to play sound in your application, but you also want to target several different platforms, each with different APIs for playing sounds. You could manually create a new project for each device you wish to support, but that could quickly turn into a nightmare as you try to keep common code in sync. That’s where preprocessor directives come in. This handy feature allows you to insert conditional logic into your source files that will include or exclude blocks of code before it gets to the Java compiler. For the purposes of this article, we will be focusing on the NetBeans implementation of preprocessor directives. First, you will need to create a configuration for each platform you wish to support. To do this, open the project properties dialog (available from the “File” menu), and click “Man...
More About: Applications , Cat , Processor , Port
Floating Point Support in Java ME
2007-03-18 04:08:00
Anyone who has been writing Java ME (J2ME) applications for a while has probably run into one of the more frustrating limitations of the platform, lack of support for the floating point primitive types: float and double. More accurately, there is no floating point support in CLDC 1.0. If you can, use CLDC 1.1, which does have floating point support. If that’s not a viable option, another possibility is to use one of the fixed point math libraries that are freely available, or to roll your own solution. One popular third-party library is MathFP, which according to the author is free for non-commercial use. Note, however, that every operation is a method call; that can turn into a lot of overhead. If you are writing an application where performance is a major concern (i.e. video games), your best bet is to roll your own fixed point math code, and implement it inline rather than through method calls. The following article provides some good examples of using inline fixed poi...
More About: Port , Support , Floating , Point
Sinfah’s Lair Reaches 20,000 Downloads
2007-03-16 15:13:00
Sinfah’s Lair reached the 20,000 download mark today on GetJar. Many thanks to everyone who has played and provided feedback! Tags: MIDlet, Java ME, J2ME, cell phone game
More About: Downloads , Download , Down , Reach , Load
Converting Audio for Use in a MIDlet
2006-10-29 21:25:00
In the tutorial Using Sprint MIDP 1.0 Extensions, we examined the use of sound APIs to play QCELP-encoded sampled sounds. This time, we will cover how to create our own sampled sound files for use in a MIDlet. Step one is to aquire a WAV file. You can create it yourself using a tool such as Windows Sound Recorder, or find a one from a royalty free sound library. Next, download the PureVoice SDK 3.1 for Windows. This SDK contains the program we will use to convert our WAV file to a QCP file. Unzip the file that you downloaded into a directory of your choosing. Last, simply drag-and-drop your WAV file onto the pvconv.exe file. The result should be a new QCP file representing your QCELP-encoded sampled sound. Now you can use play this sound file from your MIDlet using the sound APIs supported by your device. Tags: MIDlet, Java, Java ME, J2ME, QCELP, MIDP, MIDP 1.0, WAV
More About: Audio , Audi , Convert , Vert , Smiley Face
Adding a Title Screen to a MIDlet
2006-09-04 22:59:00
In a polished application, you usually want to display a title screen or splash screen before the user sees the main screen of the game or application. In this tutorial, we will build a simple application that demonstrates how to display a title screen. First, we will create a Canvas class for our title screen. In the constructor, we will create an exit command, and save a reference to the MIDlet class, so that we can call into it when the exit command is invoked. We will also save a reference to the game screen, which will be the next screen to be displayed after the title screen. In the paint() method, put the commands that will be used to draw the title screen. For this example, we will simply clear the background of the canvas, and display a centered string. Lastly, we will add code to the keyPressed() method that will switch the display to the game screen when the fire button is pressed. /* * Title Canvas.java */   import javax.microedition.lcdui.*;   /** * T...
More About: Screen , Cree
Galactic Attack Debuts
2006-08-27 16:41:00
My latest game, Gala ctic Atta ck is now available to the public. Galactic Attack is a fast-paced space shooter game for cell phones and Java-enabled mobile devices. Visit the Galactic Attack page for more information, game instructions, and free download. Tags: MIDlet, space shooter, Java, game, Java ME, J2ME, cell phone game
More About: Debut
Using RMS to Store Persistent Data
2006-07-17 02:00:00
There are times when you will want your MIDlet to be able to store data that is persistent across multiple executions of the application. In the context of video games, for example, you may want to save the high scores, or retain the game state so that the player can continue later. In this tutorial, we will look at how to use a component of MIDP called Record Management System, or RMS, as a means of storing persistent application data. The classes and interfaces related to Record Management System can be found in the javax.microedition.rms package. Persisted data is stored in a RecordStor e object. As the name implies, RecordStore objects store a collection of records. In database terminology, a RecordStore object is synonymous with a table. Each record is identified by a unique integer value, or recordId. ID values are created sequentially, with the first record having an ID of 1. An application can have multiple RecordStore objects. RecordStore objects have MIDlet Suite ...
More About: Data , Sing , Tent
Handling Key Events
2006-07-06 01:01:00
Java ME supports several input mechanisms. In a previous tutorial, we looked at the high-level commands as a means of accepting input from the user. This time, we will look at low-level key events, which are handled through the keyPressed() and keyReleased() methods. We will also look at how to use these methods in a highly interactive game or application. When the user presses a key, the application is notified by calling the keyPressed() method of the Canvas object. Similarly, when a key is released, keyReleased() is called. These methods are passed a key code which maps to the Unicode encoding of the corresponding character. Whenever possible, you should refer to the key codes using their defined constants: Canvas.KEY_NUM0 Canvas.KEY_NUM1 Canvas.KEY_NUM2 Canvas.KEY_NUM3 Canvas.KEY_NUM4 Canvas.KEY_NUM5 Canvas.KEY_NUM6 Canvas.KEY_NUM7 Canvas.KEY_NUM8 Canvas.KEY_NUM9 Canvas.KEY_STAR Canvas.KEY_POUND Additionally, MIDP provides a device independent means of mapping keys to ac...
More About: Events , Event , Hand , Vent
New Camera Phone Pictures Category
2006-06-30 02:35:00
I’ve added a new category for camera phone pictures. This is where I will post humorous or interesting pictures I’ve taken with my camera phone. More will be added as I acquire them. These were all taken using a Sanyo PM-8200. For the first post, here are a couple of pictures that probably belong on one of Jay Leno’s Headlines segments. Here in Kalamazoo, parking may be “stricltly” enforced, but apparently spelling is not. I was extremely disappointed to learn that layaway isn’t available on this buy-one-get-one-free USDA choice strip steak at Meijer. Note the fine print at the bottom of the sign. Tags: camera phone, pictures, camera phone pictures, Sanyo PM 8200, humorous pictures, Kalamazoo
More About: Pictures , Phone , Cat , Camera , Picture
Using Sprint MIDP 1.0 Extensions
2006-06-27 19:01:00
Vendor-specific APIs are useful when you need to take advantage of functionality not available in the core MIDP APIs, and you don’t mind locking your application into a single platform. I happen to have a Sprint cell phone, so we will use this as our vendor-specific example in this tutorial. First, we will learn how to use the Sprint Wireless Toolkit 3.0 platform and emulators in NetBeans IDE. Then, we will then use the Sprint MIDP 1.0 Extension s to create a MIDlet that plays sound on a Sprint PCS cell phone with only MIDP 1.0 support and no MMAPI support. First, go to the Sprint PCS Application Developer website, download the Sprint Wireless Toolkit 3.0, and install it on your development PC. This toolkit will provide you with a new platform which you can use to develop and test applications using the Sprint MIDP Extensions. Note that you must be using JDK 5.0 in order to use Sprint Wireless Toolkit 3.0. There is one additional step that must be taken in order to play QC...
More About: Print , Tension
Adding Commands
2006-06-19 04:48:00
Any MIDlet, in order to be useful, will need to accept some form of input from the user. In this article, we will look at a common form of input for MIDlets, commands. We’ll also create a sample MIDlet that responds to the corresponding events. One of the simplest ways for a MIDlet to accept input is through commands. Simply put, a command represents a specific action that can be performed by the MIDlet. How commands are presented to the user will depend on the implementation. On most cell phones, they are mapped to the two buttons directly below the LCD. If there are more than two commands, one of the buttons will bring up a menu with the remaining commands. At the very least, you will probably want to add an exit command to your application. Going back to our last demo application, lets add an exit command. First, modify the MIDlet class to implement the Comm andListener interface. public class DemoMidlet extends MIDlet implements Command Listener { Next, add an ...
More About: Commands
51245 blogs in the directory.
Statistics resets every week.


Contact | About
© Blog Toplist 2008 - Supported by Web Catalog - SEO by FeWorks
eXTReMe Tracker