Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8352263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:54:52+00:00 2026-06-09T08:54:52+00:00

Please have a look at the following code. In here, the OK button is

  • 0

Please have a look at the following code.

In here, the “OK” button is not responding.

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

public class TexyFieldExample extends MIDlet implements CommandListener
{
    private Form form;
    private Display display;
    private TextField name, company;
    private Command ok;

    public TexyFieldExample()
    {        
        name = new TextField("Name","",30,TextField.ANY);
        company = new TextField("Company","",30,TextField.ANY);
        ok = new Command("OK",Command.OK,2);

    }

    public void startApp()
    {
        form = new Form("Text Field Example");
        display = Display.getDisplay(this);

        form.append(name);
        form.append(company);
        form.addCommand(ok);

        display.setCurrent(form);

    }

    public void pauseApp()
    {

    }

    public void destroyApp(boolean destroy)
    {
        notifyDestroyed();
    }

    public void commandAction(Command c, Displayable d) 
    {
        String label = c.getLabel();

        if(label.equals("ok"))
        {
            showInput();
        }
    }

    private void showInput()
    {
        form = new Form("Input Data");
        display = Display.getDisplay(this);

        form.append(name.getString());
        form.append(company.getString());

        display.setCurrent(form);

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:54:54+00:00Added an answer on June 9, 2026 at 8:54 am

    In this code snippet commandAction won’t be invoked because you forgot to setCommandListener:

    Sets a listener for Commands to this Displayable…

    In startApp, this would look about as follows:

        //...
        form.addCommand(ok);
        // set command listener
        form.setCommandListener(this);
        //...
    

    Also, as pointed in another answer, even after you set the listener, it will miss the command because code checks it wrong – in Java, "ok" does not equals "OK".

    Actually, given that there’s only one command here, there is no need to check in the commandAction – you can proceed straight into showInput there – again, until there’s only one command.


    Another thing worth adding in this code snippet is logging.

    With appropriate logging, it would be dead easy to just run code in emulator, look into console and find out that eg commandAction isn’t invoked at all, or that command isn’t detected properly:

    // ...
    public void commandAction(Command c, Displayable d) 
    {
        String label = c.getLabel();
        // log the event details; note Displayable.getTitle is available since MIDP 2.0
        log("command  s [" + label + "], screen is [" + d.getTitle() + "]");
    
        if(label.equals("ok"))
        {
            // log detection of the command
            log("command obtained, showing input");
            showInput();
        }
    }
    
    private void log(String message)
    {
        // show message in emulator console
        System.out.println(message);
    }
    // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please have a look the following code import javax.swing.*; import java.awt.event.*; import java.awt.*; public
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
Please have a look at the following code. import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.*;
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;
am new here. i have a slight problem; PLease look at the following code
Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout;
Please have a look at the following code package normal; import java.io.*; import java.util.*;
Please have a look at the following code Main.Java import java.awt.event.*; import java.awt.*; import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.