Code:
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class MovieBookingMidlet extends MIDlet implements CommandListener
{
private RecordStore rs = null; // Record store
private Display display; // Reference to Display object
private List menu; // List object reference
private Form writeForm; // Write records screen
private Form readForm; // Read records screen
private Form deleteForm; // Delete records screen
private Form searchForm; // Search records screen
private TextField textName; // Input name
private ChoiceGroup Movie;
// private DateField date;
//private TextField textDate; // Input phone
//private TextField textCategory;
// private TextField textStatus;
private TextField textSearch; // Input search
private Command backCommand = new Command("Back", Command.BACK, 1);
private Command deleteCommand = new Command("Delete", Command.EXIT, 1);
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Command writeCommand = new Command("Write", Command.OK, 1);
private Command findCommand = new Command("Find", Command.OK, 1);
static final String REC_STORE = "db_lab10"; // Name of record store
private TextField textPhone;
private TextField textMovie;
private String movieName;
private ChoiceGroup timing;
private String Timing;
private ChoiceGroup date;
private String mDate;
private ChoiceGroup NoTic;
private String noTic;
public MovieBookingMidlet()
{
// create a list menu
menu = new List("Movie Booking", Choice.IMPLICIT);
menu.append("Book", null);
menu.append("View", null);
menu.append("Delete", null);
menu.append("Search", null);
Movie = new ChoiceGroup("Select Movie", Choice.EXCLUSIVE);
Movie.append("Titanic", null);
Movie.append("X-Men",null);
// add an exit command & register command listener for list menu
menu.addCommand(exitCommand);
menu.setCommandListener(this);
}
public void destroyApp(boolean unconditional)
{
// Close record store
closeRecStore();
// Remove the record store
// deleteRecStore();
menu = null;
writeForm = null;
}
public void startApp()
{
// Create the record store
openRecStore();
// Read back the records
// readStream();
// get reference to Display object
display = Display.getDisplay(this);
// set list menu visible
display.setCurrent(menu);
}
public void pauseApp()
{
}
public void commandAction(Command c, Displayable d)
{
Alert alert;
if (d == menu)
{
if (c == List.SELECT_COMMAND)
{
int selectedIndex = menu.getSelectedIndex();
// debugging only
// System.err.println(menu.getString(selectedIndex));
if (menu.getString(selectedIndex).equals("Book"))
{
// try to dispose of write form first
writeForm = null;
// create a form for write records screen
writeForm = new Form("Book Movies");
// create 2 TextFields for write records screen
textName = new TextField("Name:", "", 50, TextField.ANY);
textPhone = new TextField("Phone No:", "", 9, TextField.NUMERIC);
date = new ChoiceGroup("Select Available Date", Choice.POPUP);
date.append("23/1/11", null);
date.append("24/1/11",null);
date.append("25/1/11",null);
date.append("26/1/11",null);
timing = new ChoiceGroup("Select timing", Choice.POPUP);
timing.append("7pm", null);
timing.append("9pm",null);
timing.append("11pm",null);
timing.append("1am",null);
Movie = new ChoiceGroup("Select Movie", Choice.POPUP);
Movie.append("Titanic", null);
Movie.append("X-Men",null);
Movie.append("Transformer",null);
Movie.append("Harry Porter",null);
NoTic = new ChoiceGroup("No Of Tickets", Choice.POPUP);
NoTic.append("1", null);
NoTic.append("2", null);
NoTic.append("3", null);
NoTic.append("4", null);
NoTic.append("5", null);
NoTic.append("6", null);
NoTic.append("7", null);
NoTic.append("8", null);
NoTic.append("9", null);
NoTic.append("10", null);
writeForm.append(textName);
writeForm.append(textPhone);
writeForm.append(date);
writeForm.append(timing);
writeForm.append(Movie);
writeForm.append(NoTic);
// add a back command & register command listener for write records screen
writeForm.addCommand(backCommand);
writeForm.addCommand(writeCommand);
writeForm.setCommandListener(this);
// set write form visible
display.setCurrent(writeForm);
}
else if (menu.getString(selectedIndex).equals("View"))
{
// try to dispose of read form first
readForm = null;
// create a form for read records screen
readForm = new Form("View Bookings");
// add a back command & register command listener for read records screen
readForm.addCommand(backCommand);
readForm.setCommandListener(this);
// print out the results to the screen
int count = readRecordStore(readForm);
if (count == 0)
{
alert = new Alert("Info", "No Bookings are found.", null, AlertType.INFO);
display.setCurrent(alert, menu);
}
else
{
// set read form visible
display.setCurrent(readForm);
}
}
else if (menu.getString(selectedIndex).equals("Delete"))
{
// try to dispose of delete form first
deleteForm = null;
// create a form for delete records screen
deleteForm = new Form("Delete Records");
// create 2 TextFields for delete records screen
textName = new TextField("Name:", "", 50, TextField.ANY);
textPhone = new TextField("Phone:", "", 9, TextField.NUMERIC);
textMovie = new TextField("Movie","",50, TextField.ANY);
// append 2 TextFields for delete records screen
deleteForm.append(textName);
deleteForm.append(textPhone);
deleteForm.append(textMovie);
// add a back command & register command listener for delete records screen
deleteForm.addCommand(deleteCommand);
deleteForm.addCommand(backCommand);
deleteForm.setCommandListener(this);
// set delete form visible
display.setCurrent(deleteForm);
}
}