In order to use Turkish characters/letters ç,ğ,ı,ş,ö,ü,Ç,Ğ,İ,Ş,Ö,Ü in applications, their corresponding unicode character codes can be helpful.
Turkish Unicode Characters/Letters :
ç --> \u00E7
ğ --> \u011F
ı --> \u0131
ş --> \u015F
ö --> \u00F6
ü --> \u00FC
Ç --> \u00C7
Ğ --> \u011E
İ --> \u0130
Ş --> \u015E
Ö --> \u00D6
Ü --> \u00DC
Thursday, July 23, 2009
Wednesday, July 22, 2009
Creating Buttons on J2ME Forms
StringItem can be used in order to create buttons on J2ME forms. Define a new Command variable in your Form and set it as defaultCommand for StringItem variable.
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.StringItem;
public class FormWithButton extends Form implements ItemCommandListener{
private StringItem btnLogin;
private Command cmdLogin;
public FormWithButton(String str) {
super(str);
btnLogin = new StringItem(null, "Login");
cmdLogin = new Command("", Command.OK, 1);
btnLogin.setDefaultCommand(cmdLogin);
btnLogin.setItemCommandListener(this);
append(btnLogin);
}
public void commandAction(Command cmd, Item item) {
LoginForm.show();
}
}
Thursday, July 16, 2009
Singleton Java ME Forms
Some of the mobile forms contain only static elements, which are not interacting with the user. That kind of forms are usually aimed to provide a list of command items on them, which are redirecting users to other forms. So, it is reasonable to design that classess in singleton pattern. Aim of creating a form in singleton pattern is to ensure that a class has only one instance at a time. Instead of creating an instance of that kind of mobile forms each time, you can hide the constructor from global access and make it protected.
The instance that will represent the class is placed as a static field in the class and initialized when it is not created before.
This is the 'not-thread-safe' version of singleton pattern. If you want it to be thread-safe then use locking. In order to call an instance of the above class you can type in your caller:
SingletonForm.createNew().showNew();
The instance that will represent the class is placed as a static field in the class and initialized when it is not created before.
import javax.microedition.lcdui.Form;
public class SingletonForm extends Form {
private static SingletonForm instance;
public static SingletonForm createNew() {
if(instance == null){
instance = new SingletonForm("");
}
return instance;
}
public void showNew() {
MainMidlet.getInstance().getDisplay().setCurrent(this);
}
protected SingletonForm(String str){
super(str);
append("SingletonForm!");
}
}
This is the 'not-thread-safe' version of singleton pattern. If you want it to be thread-safe then use locking. In order to call an instance of the above class you can type in your caller:
SingletonForm.createNew().showNew();
Subscribe to:
Posts (Atom)
