// 6/22/09 M. Brenner import javax.microedition.lcdui.*; public class Convertio { static private final int MAXWIDTH = 10; private Command convert_, exit_, setup_; private ConvertGui gui_; private Form form_; private TextField euros_, dollars_; public Convertio (ConvertGui gui) { String rate; gui_ = gui; form_ = new Form ("Convert"); dollars_ = new TextField ("Dollars", "", MAXWIDTH, TextField.DECIMAL); form_.append (dollars_); euros_ = new TextField ("Euros", "", MAXWIDTH, TextField.DECIMAL); form_.append (euros_); rate = Preferences.getinstance().getpreference ("RATE"); form_.append (new StringItem ("", "(Rate: " + rate + ")")); exit_ = new Command ("Exit", Command.EXIT, 0); form_.addCommand (exit_); convert_ = new Command ("Convert", Command.OK, 0); form_.addCommand (convert_); setup_ = new Command ("Setup", Command.OK, 0); form_.addCommand (setup_); form_.setCommandListener (new CommandListener() { public void commandAction (Command c, Displayable disp) { if (c == convert_) { convert(); } else if (c == exit_) { gui_.exit(); } else if (c == setup_) { gui_.setprefs(); } } }); } private void convert() { double converted, rate, value; Converter converter; String text; TextField dest; rate = Double.parseDouble (Preferences.getinstance().getpreference ("RATE")); if ((text = euros_.getString()).length() > 0) { dest = dollars_; value = Double.parseDouble (text); rate = 1/rate; } else { dest = euros_; value = Double.parseDouble (dollars_.getString()); } converter = new Converter (rate); dest.setString (converter.convert (value) + ""); } public Form getform() { return form_; } }