Archive for November, 2009

JavaME Library you might need

I have this javame library I have been compiling for a while. It has a lot of small small code snippets and classes I use often, there is a database part where I have tried as much as possible to encapsulate parts of the saving/retrieving parts of RMS, there is also the UI part, which is what I want to talk about today.

This part contains a TickerForm, which is a form that can show scrollable contents pulled from database or URL at intervals(I am yet to finish it) and the second thing is the Controllable form. This form has a Controller that you can use to service the form(just like posting a form through POST). You call the submit() method of the form and the service method of the controller is called. The service method stores the values of items of the form in a Properties object(which is basically a key-value pair). A code is worth more than a thousand words they say, so here we are

* To change this template, choose Tools | Templates
* and open the template in the editor.
package com.trinisoft.atpay.forms;

import com.trinisoft.atpay.MainForm;
import com.trinisoft.atpay.helpers.RecordStores;

import com.trinisoft.mlib.db.decorator.StoreDecorator;
import com.trinisoft.mlib.login.LoginForm;
import com.trinisoft.mlib.login.db.UserClass;
import com.trinisoft.mlib.ui.Form;
import com.trinisoft.mlib.util.Controller;
import com.trinisoft.mlib.util.Properties;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextField;
import javax.microedition.rms.RecordStoreException;

* @author trinisoftinc
public class RegisterForm extends Form {

TextField username, password, cpassword;
Command ok, cancel;
LoginForm loginForm;
RecordStores recordStores;
MainForm mainForm;
Display display;

public RegisterForm(LoginForm loginForm, final RecordStores recordStores, MainForm mainForm, Display display) {
super("Register", new Controller() {

public boolean service(Properties properties) {
String username = properties.getParameter("Username").toString();
String password = properties.getParameter("Password").toString();
String cpassword = properties.getParameter("Confirm Password").toString();

if (password.equals(cpassword)) {
UserClass userClass = new UserClass();
try {
new StoreDecorator(userClass).save(recordStores.getUserRecordStore());
properties.setParameter("response-code", new Integer(200));
properties.setParameter("response-text", "Password Mismatch");
} catch (RecordStoreException ex) {
} catch (IOException ex) {
} else {
properties.setParameter("response-code", new Integer(500));
properties.setParameter("response-text", "Password Mismatch");
return true;
this.loginForm = loginForm;
this.recordStores = recordStores;
this.mainForm = mainForm;
this.display = display;

private void init() {
username = new TextField("Username", "", 255, TextField.ANY);
password = new TextField("Password", "", 255, TextField.PASSWORD);
cpassword = new TextField("Confirm Password", "", 255, TextField.PASSWORD);
ok = new Command("Submit", Command.OK, 0);
cancel = new Command("Quit", Command.EXIT, 0);


setCommandListener(new CommandListener() {

public void commandAction(Command c, Displayable d) {
if (c.equals(ok)) {
if(getResponseCode() == 200) {
} else {
Alert l = new Alert("Error Occurred",getResponseText(),null,AlertType.ERROR);
} else if (c.equals(cancel)) {

You should draw your attention to two places, the contructor and the commandAction in the init() method. In the super constructor, you pass in a Controller, the controller have a service method, which handles the forms submit() and stores response-code and reponse-text keys and values in the Properties passed to it. These keys are used in the commandAction to get the response code and value. Any other value(or object for that matter) that you want to send back as response can be stored in the Properties object.

I think this suite of classes would be useful for anyone interested in Java ME development. Try it out and let me know your feedbacks.

Code hosted at



Comments (2)

iPhone not Charging.

I have this problem with my iPhone, Whenever I run the battery down to less than 20%, the phone won’t charge again when I plug it in my MAC. But if I plug it in windows it will charge, if and only of the windows box is not been used. If the windows PC is in use, then no charging for iPhone. Of recent, the iPhone started behaving very funny too. Sometimes, the MAC will charge it sometimes it won’t. So I decided to look for reasons why.

First I note that when the battery is below 20%, before you plug it in, shut it down first, then plug it in and everything will be fine. Next, The iPhone will charge if iTunes is not running before you plug it in. If iTunes is running, then you have to close iTunes and open it again, and iPhone is charging. Next I also noticed that most of the electric chargers that ship with the iPhone will not work for you once you jailbreak the iPhone.

The iPhone is a great product, but when people complain about the battery, I think it goes beyond the mere fact that it runs down quickly, the battery of the iPhone is generally shitty, You will be surprised at the vast amount of people who have posted online about this(google is your friend) and yet, apple seems to not want to do anything about it! Although this problem of not charging seems to be experienced by mostly people who jailbroke their iPhones.

Anyway, after about 4hours, today I now know exactly the voodoos I have to invoke to make the iPhone charge anytime anyday anywhere…..I pity the less tech savvy people who use jail broken iPhones.

Comments (1)

Java ME EA on MAC

This is my experience with the JavaME EA for MAC OS. I am using 10.5.8(Leopard).

At first it was a God sent that we now have a tool from sun. Using Netbeans and mpp-sdk kinda sucks, but it was all I have got. After the download, which went without incidents, I ran the EA for the first time and it blew all the whistles and knock all the bells. I immediately opened a sample app and run it, It ran well without incidents. Then out of the blue, I got the first error.

When trying to run ANY application, it will return with an exception/error message that it can not connect to device 0, or any of the devices I used at that. I googled and all the responses were not helping me at all. At last I did the unthinkable, guess what that is? I restarted my MAC. I have not done that in a looooooong while so it took some time before the system actually finished the restarting process and voila, my EA was back online. But not for long!

Next, EA takes it upon itself to just DIE for no reason. I run an app, and the next thing is the EA has stopped working un-expectedly. I also tried googling, but no result. So I started fooling around. I went to tools and refresh the SDK under platforms and voila again, EA stops dying. But again, that was not all.

Next I noticed that after running an app for about 6 to 10 times, EA will stop working saying it has run of memory. I tried to close all applications while running EA but, duh! after about 6 to 10, sometimes 15 runs, it will stop working with the same out of memory error. The annoying thing is, it won’t even quit. I will have to use force quit(windows version of CTRL + ALT + DEL).

I am yet to solve this problem, and I don’t think I will ever solve it until the next version comes out. Looking back however to the days of mpp-sdk and Netbeans, I think I still prefer the EA, At least I can do Bluetooth without having to buy some licence from some people.

All in all, I give Sun +1 on this. It is really something all MAC developers have been asking for since time immemorial. All that remains is perfection. And if I remember correctly, in software, attaining perfection is an eternal process. No software is perfect until it is dead.

One thing I will give kudos to the EA guys for again is that, all projects created on Netbeans also works perfectly on EA, be it from windows or linux. +1 to you guys again on that.

Finally, EA is a good product. If you are a MAC J2ME developer, you will enjoy this IDE.

Comments (11)