前の画面に戻るコマンドを作成する方法を見つけようとして立ち往生しています。
戻ろうとしているページにはフォームではなくリストがありますが、
「戻る」コマンドリスナーをリストに設定すると、null ポインター例外がスローされるようです。
これが私のメインクラスです
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
/**
*
*/
public class CalFrontEnd extends MIDlet implements CommandListener
{
private Display display;
protected List list = new List("Please Select a Option", List.IMPLICIT);
private Command select = new Command("Select", Command.SCREEN, 1);
private Command exit = new Command("Exit", Command.EXIT, 2);
private Command save = new Command("Save,", Command.SCREEN, 2);
private DateField calendar;
/**
*
*/
public CalFrontEnd()
{
display = Display.getDisplay(this);
list.append("Select Date", null);
list.append("Add Events", null);
list.append("Remove Events", null);
list.append("Browse Events", null);
list.addCommand(select);
list.addCommand(exit);
list.setCommandListener(this);
}
/**
* Start Application
*/
public void startApp()
{
display.setCurrent(list);
}
/**
* Pause Application Method
*/
public void pauseApp()
{}
/**
* Destroy Application Method
*/
public void destroyApp(boolean unconditional)
{}
/**
*
* @param command
* @param displayable
*/
public void commandAction(Command command, Displayable displayable)
{
if (displayable == list) {
if (command == List.SELECT_COMMAND) {
switch (list.getSelectedIndex()) {
case 0: // select Date
SelectDate myDate = new SelectDate(display);
myDate.BuildCalendar();
break;
case 1: //add Events
AddEvents myAEvents = new AddEvents(display);
myAEvents.BuildAddEvents();
break;
case 2: //Remove Events
RemoveEvents myREvents = new RemoveEvents(display);
myREvents.BuildRemoveEvents();
break;
case 3: //Browse Events
BrowseEvents myBEvents = new BrowseEvents(display);
myBEvents.BuildBrowseEvents();
break;
}
} else if (command == exit) {
destroyApp(false);
notifyDestroyed();
}
}
}
}
そして、これは私が戻るボタンを使用しようとしているクラスです
import java.util.*;
import javax.microedition.lcdui.*;
/**
*
*/
public class SelectDate extends CalFrontEnd implements CommandListener
{
private DateField calendar;
private Form form = new Form("Please Select a Date");
private Command select = new Command("Select", Command.SCREEN, 1);
private Command back = new Command("Back", Command.BACK, 2);
private Command save = new Command("Save,", Command.SCREEN, 2);
private Display display;
/**
*
*/
public SelectDate(Display display)
{
this.display = display;
}
/**
*
*/
public void BuildCalendar()
{
calendar = new DateField("Date In :", DateField.DATE, TimeZone.getTimeZone("GMT"));
form.append(calendar);
form.addCommand(back);
form.setCommandListener(this);
display.setCurrent(form);
}
/**
*
* @param command
* @param displayable
*/
public void commandAction(Command command, Display display)
{
if (command == back)
{
display.setCurrent(list);
}
}
}