import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.*; import javax.microedition.io.*; import javax.microedition.io.file.*; import java.util.Timer; import java.util.TimerTask; import java.util.*; //show menus to set the interval and the folder name public class test extends MIDlet implements CommandListener{ Alert folderAlert; TextField durationField; TextField setnameField; Form mainMenuForm; StringItem runningString; Form runningForm; Timer mainTimer; CameraTask camTask; boolean running = false; Display display; public test () { System.out.println("Started v0.1"); //start form setup mainMenuForm = new Form("Setup"); folderAlert = new Alert ("Folder error"); folderAlert.setString("Folder exception"); durationField = new TextField("Delay(s)", "60", 4, TextField.NUMERIC); setnameField = new TextField("Set name", "new", 8, TextField.ANY); mainMenuForm.append(durationField); mainMenuForm.append(setnameField); mainMenuForm.addCommand (new Command ("Exit", Command.EXIT,2)); mainMenuForm.addCommand (new Command ("Go", Command.OK,1)); mainMenuForm.setCommandListener(this); //running form setup runningForm = new Form ("Running "); runningString = new StringItem("Running..",""); runningForm.append(runningString); runningForm.addCommand (new Command("Stop", Command.CANCEL,2)); runningForm.setCommandListener(this); //camera timer mainTimer = new Timer(); } public void commandAction(Command com, Displayable disp){ String label = com.getLabel(); if(label.equals("Exit")){ System.out.println ("exit pushed"); notifyDestroyed(); } else if (label.equals("Go")){ startCapture(); } else if (label.equals("Stop")){ stopCapture(); } } private void startCapture(){ //create a folder for the pictures createFolder("file:///e:/MSSEMC/Media files/other/"+setnameField.getString()+"/"); //set the running flag as true running = true; //create a new cameratask camTask = new CameraTask(setnameField.getString()); //start it long time = 1000 * Long.parseLong(durationField.getString()); mainTimer.scheduleAtFixedRate(camTask, 1000, time); //probably should change the current form System.out.println("change form"); display.setCurrent(runningForm); } private void stopCapture(){ mainTimer.cancel(); display.setCurrent(mainMenuForm); } public void createFolder(final String path){ new Thread(){ public void run(){ try{ FileConnection fConn = (FileConnection)Connector.open(path); if(!fConn.exists()){ fConn.mkdir(); } fConn.close(); }catch(Exception e){ e.printStackTrace(); display.setCurrent(folderAlert); } } }.start(); } public void startApp() { display = Display.getDisplay(this); display.setCurrent(mainMenuForm); } public void pauseApp() { } public void destroyApp(boolean unconditional){ } }