Code:
Package cn.edu. xtu. tilepuzzle. UI;
Import java. Io. ioexception;
Import java. util. vector;
Import javax. microedition. lcdui .*;
Import cn.edu. xtu. tilepuzzle. gamedb;
Import cn.edu. xtu. tilepuzzle. contorler. mainuicontroller;
Import cn.edu. xtu. tilepuzzle. model. boardmodel;
Import cn.edu. xtu. tilepuzzle. model. classlistitem;
Public class showphotoui extends canvas implements commandlistener {
Mainuicontroller;
Display display;
Boardmodel;
Displayable;
// String orgimagestring;
Command OK;
Command cancel;
String imgpathstring = "";
Image IMG = NULL;
Public showphotoui (string imgpathstring, mainuicontroller,
Boardmodel, display, displayable ){
This. boardmodel = boardmodel;
This. Display = display;
This. displayable = displayable;
This. mainuicontroller = mainuicontroller;
This. imgpathstring = imgpathstring;
Init ();
}
Public void Init (){
OK = new command ("OK", command. OK, 0 );
Cancel = new command ("return", command. Cancel, 1 );
This. addcommand (OK );
This. addcommand (cancel );
This. setcommandlistener (this );
Try {
IMG = image. createimage (imgpathstring );
} Catch (ioexception e ){
E. printstacktrace ();
}
}
Public void commandaction (command arg0, displayable arg1 ){
If (arg0 = OK ){
Mainuicontroller. ischangegamedata = true;
System. Out. println ("OK ");
Boardmodel. gamesetdata [gamedb. indexingamesetdatat_orgimagestring] = This. imgpathstring;
Boardmodel. orgimage = This. IMG;
// Update user data to the mobile phone record set
Boardmodel. stroegamedata ();
// Obtain the original mobile phone information from the mobile phone record set again
Boardmodel. initgamedata ();
// Re-initialize the puzzle Information
Boardmodel. initdata ();
This. display. setcurrent (mainuicontroller. mainmenuui );
} Else if (arg0 = Cancel ){
System. Out. println ("return ");
This. display. setcurrent (displayable );
}
}
Protected void paint (Graphics g ){
G. setcolor (0, 0, 0 );
G. fillrect (0, 0, getwidth (), getheight ());
G. drawimage (IMG, 0, 0, graphics. Left | graphics. Top );
}
}
Runtime Interface