Dear All,
I am very new to JavaME programming and am trying to write a very simple program that simply appens a string to my form when a command is run. However whatever I do, nothing seems to happen when I click the soft command button. My code is as follows:
public class HelloMIDlet extends MIDlet implements CommandListener
{
private Command exitCommand; // The exit command
private Display display; // The display for this MIDlet
private Command switchFormCommand;
private Form mForm;
private String messages;
private String messages2;
public HelloMIDlet()
{
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 0);
switchFormCommand = new Command("SwitchForm", Command.OK,2);
}
public void startApp()
{
Form mForm = new Form("Change Date");
java.util.Date now = new java.util.Date();
DateField dateItem = new DateField("Today's date:", DateField.DATE);
dateItem.setDate(now);
String messages = new String ("Welcome, glad you could come.");
String messages2 = new String ("Thank you for clicking that button");
mForm.append(dateItem);
mForm.append(messages);
mForm.addCommand(exitCommand);
mForm.addCommand(switchFormCommand);
mForm.setCommandListener(this);
display.setCurrent(mForm);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void updatedisplay()
{
mForm.append(messages2);
}
public void commandAction(Command c, Displayable s)
{
String label = c.getLabel();
if (c == exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
if(label.equals("SwitchForm"))
{
updatedisplay();
}
}
}
The CommandAction() function works and does recognise when the 'SwitchForm' command is passed to it, but the commands in the updatedisplay() function don't seem to do anything, ie nothing is added to the display.
Do I need to issue some code in my updatedisplay() function that gets the display before issuing the form.append command?
Thanks in advance for any help,
Phil

Reply With Quote


