i have done it using the following class :
public class passwordTextField extends EditField
{
private final static String INIT_TEXT = "Enter Password";
protected void paint(Graphics graphics)
{
String originalText = getText();
String fakeText = originalText;
if (originalText.equalsIgnoreCase(""))
{
fakeText = isFocus() ? originalText : INIT_TEXT;
}
else
{
if(LogInPage.flag == true)
{
setText(originalText);
}
else
{
fakeText = "";
for (int i=0 ; i<originalText.length();i++)
{
fakeText += '*';
}
}
}
setText(fakeText);
super.paint(graphics);
setText(originalText);
}
}
and call this class in main screen as follows:
passwordTextField password = new passwordTextField();
add(password);
and add change listener to showpassword check box
static boolean flag = false;
public void fieldChanged(Field field, int context)
{
if(showPasswordCheckbox.getChecked() == true)
{
flag = true;
}
else
{
flag = false;
}
}