0 Replies - 528 Views - Last Post: 24 November 2010 - 12:16 PM

#1 Guest_mike55*


method call from a list?

Posted 24 November 2010 - 12:16 PM


I have an assignment where I need to create a unit converter. I create a list for all the conversion choices, bu I'm having a lot of difficulty linking the list option to the method that would open a new form and do the calculation. right now I'm trying to link list choice Convert Weight to the method convertWeight()

Anything you can add would be appreciated.

Here is my code so far. Thanks again .

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

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Date;

 * @author
public class ConverterFinal extends MIDlet implements CommandListener,
    private Display display = null;

    private static String strConvertDistance = "Convert Distance";
    private static String strConvertArea = "Convert Area";
    private static String strConvertWeight = "Convert Weight";
    private static String strConvertHeight = "Convert Height";
    private static String strConvertVolume = "Convert Volume";
    private static String strConvertTemperature = "Convert Temperature";
    private static String strConvertSpeed = "Convert Speed";
    private static String strConvertAngle = "ConvertAngle";
    private static String strConvertEnergy = "ConvertEnergy";

    //Declaring the menu
    List menu = null;
    Form ui_form = null;
    StringItem si = null;

    TextField VTC;//VTC = Value To Convert

    //Declaring the Welcome message
    Alert welcome;
    Command Done;

    //Declaring Commands
    Command Convert;
    Command ConvertArea;

    Command Quit;
    Command QuitApp;

    public ConverterFinal()
        Done = new Command("Done", Command.SCREEN, 1);
        Quit = new Command("Quit", Command.SCREEN, 2);
        QuitApp = new Command("Quit", Command.SCREEN, 1);

        Convert = new Command("Convert", Command.ITEM, 1);
        ConvertArea = new Command("Convert Area", Command.ITEM, 1);
    }//End Converter constructor
    public void startApp() 
        display = Display.getDisplay(this);
    }//End startApp()

    public void pauseApp() 

    }//End pauseApp()

    public void destroyApp(boolean unconditional) 
    }//End destroyApp()

    public void commandAction(Command c, Displayable d)
        if ( c == Done )
        }//END DONE IF

        if ( c == QuitApp )
        }//End if ( c == QuitApp )

        else if(c.getCommandType() == Command.BACK)
        }//end else if(c.getCommandType() == Command.BACK)
        else if (c == List.SELECT_COMMAND)
            Form ui_form = new Form("Working...");
            Thread thread = new Thread(this);
        }//end  else if (c == List.SELECT_COMMAND)

    }//End commandAction

    public void run()
        int index = menu.getSelectedIndex();
        if(index == -1) return;
        String command = menu.getString(index);
        if (command.equals(strConvertDistance)) convertDistance();
        else if (command.equals(strConvertArea)) convertArea();
        else if (command.equals(strConvertWeight)) convertWeight();
        else if (command.equals(strConvertHeight)) convertHeight();
        else if (command.equals(strConvertVolume)) convertVolume();
        else if (command.equals(strConvertTemperature)) convertTemperature();
        else if (command.equals(strConvertSpeed)) convertSpeed();
        else if (command.equals(strConvertAngle)) convertAngle();
        else if (command.equals(strConvertEnergy)) convertEnergy();
    }//End run()

     public void welcome()
        display = Display.getDisplay(this);

        welcome = new Alert("Welcome to the Unit Converter!!!", "", null, AlertType.INFO);
        welcome.setString(new Date().toString());

    }//END welcome()

    public void showMenu()
        menu = new List("Converter", List.IMPLICIT);

        menu.append(strConvertDistance, null);
        menu.append(strConvertArea, null);
        menu.append(strConvertWeight, null);
        menu.append(strConvertHeight, null);
        menu.append(strConvertVolume, null);
        menu.append(strConvertTemperature, null);
        menu.append(strConvertSpeed, null);
        menu.append(strConvertAngle, null);
        menu.append(strConvertEnergy, null);


    }//END showMenu();

     * Converter methods

    public void convertDistance()

    public void convertArea()

    public void convertWeight()
        double result;
        double constant = 2;

        ui_form = new Form("Convert Weight");

        VTC = new TextField("Enter Weight to Convert", "", 50, TextField.DECIMAL);

        //i = Double.parseDouble(VTC.getString());

        result = Double.parseDouble(VTC.getString()) * constant;


        //Invoking Action Listener

    }//End cconvertWeight()

    public void convertHeight()

    public void convertVolume()

    public void convertTemperature()

    public void convertSpeed()

    public void convertAngle()

    public void convertEnergy()
}//End public class ConverterFinal

Is This A Good Question/Topic? 0

Page 1 of 1