1 Replies - 10684 Views - Last Post: 17 August 2010 - 11:08 PM

#1 elf_rox_2007   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-July 10

J2ME TextField Events or Key Listeners

Posted 17 August 2010 - 07:02 AM

Hello eveybody,

I am new to J2ME Programming so i am stuck with the listeners thing.

When programming in JavaSE, we can use listeners to handle events, however after seeing the J2ME reference i see that there are very few listeners which have confused me.

I am writing a simple J2ME app in which there are 3 textfields. As soon as the user types a char in first textfield the result must be displayed in second and third textfield i.e. I want to handle the events of changes in data of TextField. Can any body tell what listener to use for it and how to do it ???

Here is what i have tried to make the gui, but can't go further as I dont know how to listen to keypad events or TextField changes....

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

package kalc;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import kalc.TextFieldItem;

 * @author Administrator
public class KalcMIDlet extends MIDlet implements CommandListener{

    private Command exitCommand;
    private Command aboutCommand;

    private Form mainForm;

    private TextField tf2 = new TextField("Hexadecimal Output:","",15,TextField.NUMERIC);
    private TextField tf3 = new TextField("Binary Output:","",15,TextField.NUMERIC);
    private TextField tf4 = new TextField("Octal Output:","",15,TextField.NUMERIC);

    public KalcMIDlet(){

        exitCommand = new Command ("EXIT",Command.EXIT,2);
        aboutCommand = new Command("ABOUT",Command.ITEM,1);

        mainForm = new Form("Calc");

    public void startApp() {




    public void pauseApp() {

    public void destroyApp(boolean unconditional) {

    public void commandAction(Command c, Displayable s) {

            Alert a = new Alert("About", "About text", null, AlertType.INFO);


Thanks in advance....

Is This A Good Question/Topic? 0
  • +

Replies To: J2ME TextField Events or Key Listeners

#2 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Re: J2ME TextField Events or Key Listeners

Posted 17 August 2010 - 11:08 PM

You will need to use an ItemStateListener.
First, your class needs to implement the ItemStateListener interface. Then you need to inform your form that you have defined an itemStateListener in the same class by using mainForm.setItemStateListener(this);

Then insert your code into the itemStateChanged() function like this:
public void itemStateChanged(Item i)
   /// insert code here

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1