Utilities

J2ME Polish contains several often needed J2ME utilty classes:

Using the BitMapFont Class

You can use the class de.enough.polish.util.BitMapFont for using bitmap fonts directly in your application. This is often useful in games and other application, when you want to show messages to the user which should not appear in the standard font-faces.

The involved concepts are quite easy:

  1. Create a bitmap font using the ${polish.home}/font-editor executable.
  2. Create a BitMapFont in your application.
  3. Use the BitMapFontViewer to display a message.

The following code illustrates the second and third step:

import de.enough.polish.util.*;

public class MyCanvas extends Canvas {

	private BitMapFont bitMapFont;
	privte BitMapFontViewer messageViewer;

	public MyCanvas() {
		this.bitMapFont = BitMapFont.getInstance("/coolfont.bmf");
		this.messageViewer = this.bitMapFont.getViewer("Hello World!");
		int availableWidth = getWidth() - 20;
		int padding = 2;
		int textOrientation = Graphics.LEFT;
		this.messageViewer.layout( availableWidth, availableWidth, padding, orientation );
	}

	public void paint( Graphics g ) {
		int x = 10;
		int y = 20;
		this.messageViewer.paint( x, y, g );
	}
}

Since the BitMapFont.getViewer(String)-method is the most expensive one, you should try to call it only when it's necessary, e.g. when a new message is generated.

Logging Framework and the Debug Class

Use the J2ME Polish logging framework with logging levels, detailed information and have a look at the log even on the device. And best of all: when it is not needed, the logging will use no memory and no processing power at all!

The logging framework of J2ME Polish consists of the #debug and #mdebug preprocessing directives and the Debug-class.

Find more information about it at following documentations:

ArrayList

J2ME Polish includes an ArrayList class, which is compatible to the J2SE class. Find more information at the JavaDoc documentation.

TextUtil

The TextUtil class contains several helper methods for text manipulation, e.g. a wrapping-algorithm and a split-tool. Have a look at the JavaDoc documentation.

JavaDoc

Please refer to the JavaDoc documentation of these classes for further information.