J2ME ask

Discussion in 'Software' started by erdy_rezki, Feb 15, 2013.

  1. erdy_rezki

    erdy_rezki Private E-2

    what must i'm add so this coding display addition, my problem is, when i click a result button at emulator j2me, the addition function not responding , can somebody tell me what i supposed to do? thanks before :)
    Code:
    
    package org.itmaranatha.MobileTest1;
    
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    
    /**
     * @author Erdy rezki
     */
    public class MidletPraktikum extends MIDlet {
    
        private Command cmdAdd, cmdResult, cmdExit, cmdClear;
        private int bil1, bil2, hasil = 0;
        private TextBox txtBox;
    
        public MidletPraktikum() {
            txtBox = new TextBox("", "", 100, 5);
            cmdAdd = new Command("Add", Command.SCREEN, 0);
            cmdResult = new Command("Result", Command.SCREEN, 0);
            cmdExit = new Command("Exit", Command.EXIT, 0);
            cmdClear = new Command("Clear", Command.SCREEN, 0);
    
            txtBox.addCommand(cmdAdd);
            txtBox.addCommand(cmdExit);
    
            txtBox.setCommandListener(new CommandListener() {
    
                public void commandAction(Command c, Displayable d) {
                    if (c.equals(cmdAdd)) {
                        bil1 = Integer.parseInt(txtBox.getString());
                        txtBox.setString("");
                        txtBox.removeCommand(cmdAdd);
                        txtBox.addCommand(cmdResult);
                        
                    } else if (c.equals(cmdResult)) {
                        bil2 = Integer.parseInt(txtBox.getString());
                        hasil = bil1 + bil2;
                        txtBox.setString(" Result from " + bil1 + "+" + bil2 + "is" + hasil);
                        txtBox.removeCommand(cmdClear);
    
                    } else if (c.equals(cmdClear)) {
                        txtBox.setString("");
                        txtBox.removeCommand(cmdClear);
                        txtBox.setConstraints(5);
                        txtBox.removeCommand(cmdResult);
    
                    } else if (c.equals(cmdExit)) {
                        destroyApp(true);
                        notifyDestroyed();
                        notifyDestroyed();
    
                    }
                }
            });
        }
    
        public void startApp() {
            Display.getDisplay(MidletPraktikum.this).setCurrent(txtBox);
        }
    
        public void pauseApp() {
        }
    
        public void destroyApp(boolean unconditional) {
        }
    }
    
    
     
  2. PC-XT

    PC-XT Master Sergeant

    You don't have
    Code:
    txtBox.addCommand(cmdResult);
    txtBox.addCommand(cmdClear);
    so I doubt those commands are active.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds