2 Replies - 1326 Views - Last Post: 31 October 2011 - 04:02 PM

#1 dal3y  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-May 10

Working on a Pizza/Burger MIDlet project

Posted 31 October 2011 - 12:29 PM

So I'm working on writing a MIDlet that asks the following questions:
  • Pizza or Burger?
  • If it's Pizza, ask for each of the following toppings: pepperoni, sausage, anchovies
  • If Burger, ask for cheese and onions


I'm trying to construct separate alerts or change the String property of a given alert. I'm also trying to use the Commannd object with the alert.

However, this is what I have so far, and it appears that I have gotten it all wrong:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

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

/**
 * @author Class
 */

public class AlertMidlet extends MIDlet implements CommandListener {
    Alert mymsg,mymsg2;
    Display disp;
    Command nextalert;
    Form myform;
    TextField username, password;
            
    public AlertMidlet() {
        mymsg = new Alert("PIZZA");
        mymsg.setString("I would like a pizza with pepperoni, sausage,"
                + "and anchovies.");
        mymsg.setTimeout(10000);
        mymsg2 = new Alert("BURGER");
        mymsg2.setString("I would like a burger with onions and cheese.");
        nextalert = new Command("Next Alert",Command.OK,0);
        mymsg.addCommand(nextalert);
        mymsg.setCommandListener(this);
        
        myform = new Form("Our First Form");
        username = new TextField("Username", "", 10,TextField.ANY);
        myform.append(username);
        password = new TextField("Password", "", 10,TextField.PASSWORD);
        myform.append(password);
        myform.addCommand(nextalert); 
        myform.setCommandListener(this);
//                
    }
    public void startApp() {
     disp = Display.getDisplay(this);
     disp.setCurrent(myform);
         
    }
    
     public void commandAction(Command c, Displayable d) {
      if ((c == nextalert) && (d == myform)) {
          if (username.getString().equals(password.getString())) {
                disp.setCurrent(mymsg);
          } else {
           disp.setCurrent(mymsg2);
          }
      
       }
     }
    
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
}



I've even tried Yahoo! Answers to help me with this, but so far, I've gotten no luck on it.

I'm looking for any hints/ideas to make this MIDlet work properly.

Is This A Good Question/Topic? 0
  • +

Replies To: Working on a Pizza/Burger MIDlet project

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10781
  • View blog
  • Posts: 40,153
  • Joined: 27-December 08

Re: Working on a Pizza/Burger MIDlet project

Posted 31 October 2011 - 01:34 PM

Moved to Mobile Development.

What specific problems or errors are you encountering?
Was This Post Helpful? 0
  • +
  • -

#3 dal3y  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-May 10

Re: Working on a Pizza/Burger MIDlet project

Posted 31 October 2011 - 04:02 PM

The problem is with this part of the code:
public void commandAction(Command c, Displayable d) {
 if ((c == nextalert) && (d == myform)) {
     if (username.getString().equals(password.getString())) {
           disp.setCurrent(mymsg);
     } else {
      disp.setCurrent(mymsg2);
     }



If the username and the password are the same, it'll just display an alert for pizza, and will do the other for burger if they're not equal.

So that's why I have the code wrong.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1