Code:
Package cn.edu. xtu. tilepuzzle. model;
Import javax. microedition. lcdui. Font;
Import javax. microedition. lcdui. graphics;
Import javax. microedition. lcdui. image;
Public class classpiece {
Image IMG;
Boolean addstring = false; // whether to add the original position of the image to each square.
Int cellwidth; // The width of the square.
Int cellheight; // The height of the square
Int serial; // serial number for ordering
// The initialization position of the square
Int IX; // initial location in grid coordinates
Int Iy; // initial location in grid coordinates
// Current position of the square
Public int X; // current location in grid coordinates
Public int y; // current location in grid coordinates
Classpiece (image IMG _, int Ser, int NX, int NY, int cellwidth, int cellheight ){
IMG = IMG _;
Serial = SER;
X = IX = NX;
Y = Iy = NY;
This. cellheight = cellheight;
This. cellwidth = cellwidth;
}
Void setimg (image IMG _){
IMG = IMG _;
}
Void setlocation (int nx, int NY ){
This. x = NX;
This. Y = NY;
}
// Assumes background is white
Public void paint (Graphics g ){
Int PX = y * cellwidth; // line coordinate
Int py = x * cellheight; // column Coordinate
G. drawimage (IMG, PX, Py, graphics. Left | graphics. Top );
If (addstring ){
String STR = (1 + this. IX) + "," + (1 + this. Iy );
G. setcolor (100,100,245 );
G. setfont (font. getdefaultfont ());
G. drawstring (STR, PX + (IMG. getwidth ()-font. getdefaultfont (). stringwidth (STR)/2, Py + (IMG. getheight ()-font. getdefaultfont (). getheight ()/2, graphics. left | graphics. top );
}
}
Boolean ishome (){
Return (x = IX) & (y = Iy );
}
Public void Gohome (){
This. x = IX;
This. Y = Iy;
}
Public int getcellwidth (){
Return cellwidth;
}
Public void setcellwidth (INT cellwidth ){
This. cellwidth = cellwidth;
}
Public int getcellheight (){
Return cellheight;
}
Public void setcellheight (INT cellheight ){
This. cellheight = cellheight;
}
}
Personal Information Class, code:
Package cn.edu. xtu. tilepuzzle. model;
Import javax. microedition. lcdui. image;
Public class classpeopleinfo {
/**
Name; flag; Time
*/
Public string name = "";
Public String flag = "3x4"; // It indicates 3 columns, 4 rows, 4x5
Public long time = 0;
Public String strtime = "";
Public Image showimage;
Public Image getshowimage (){
Return showimage;
}
Public void setshowimage (image showimage ){
This. showimage = showimage;
}
Public classpeopleinfo (){
}
Public String getflag (){
Return flag;
}
Public void setflag (string flag ){
This. Flag = flag;
// System. Out. println ("setting type:" + flag );
}
Public String getname (){
Return name;
}
Public void setname (string name ){
This. Name = Name;
// System. Out. println ("Set Name:" + name );
}
Public long gettime (){
Return time;
}
Public void settime (long time ){
// System. Out. println ("set time:" + time );
This. Time = time;
String Space = "";
If (Time> = 1000 & time <10000) Space = "";
Else if (Time> = 100) Space = "";
Else if (Time> = 10) Space = "";
Else {
Space = "";
}
This. strtime = string. valueof (time) + space + "second"; // boardmodel. gettimestring (time );
}
Public String getstrtime (){
Return strtime;
}
}
Select the List class of the background puzzle, code:
Package cn.edu. xtu. tilepuzzle. model;
Import cn.edu. xtu. tilepuzzle. gamedb;
Public class classlistitem {
Public String imagedefalut_1 = gamedb. imagedefalut_1path;
Public String imagedefalut_2 = gamedb. imagedefalut_2path;
/**
* Source image address
**/
Public String photostring = "";
Public String getphotostring (){
Return photostring;
}
Public void setphotostring (string photostring ){
This. photostring = photostring;
}
/**
* Preview image address
**/
Public String iconstring = "";
/**
* Default image
*/
Private string defaultimagepath = "";
/**
* Group
*/
Public static int group = 1;
/**
* Record
*/
Public static int item = 0;
/**
* Select or not
*/
Private Boolean ifselected = false;
/**
* Display label
*/
Private string label;
/**
* Type: group, record
*/
/**
* Storage objects
*/
Private object content;
Public int indexinitemlist = 0;
Public int getindexinitemlist (){
Return indexinitemlist;
}
Public void setindexinitemlist (INT indexinitemlist ){
This. indexinitemlist = indexinitemlist;
}
Private int type;
Public classlistitem (Object content, string photostring, string iconstring, string label, int type, Boolean isselect, int indexinitemlist ){
This. iconstring = iconstring;
This. photostring = photostring;
// System. Out. println ("22222222 ");
// System. Out. println (iconstring );
This. Label = label;
This. type = type;
This. content = content;
This. indexinitemlist = indexinitemlist;
This. setifselected (isselect );
}
Public void seticonstring (string iconstring ){
This. iconstring = iconstring;
}
Public String getlabel (){
Return label;
}
Public void setlabel (string label ){
This. Label = label;
}
Public int GetType (){
Return type;
}
Public void settype (INT type ){
This. type = type;
}
Public Boolean ifselected (){
Return ifselected;
}
Public void setifselected (Boolean ifselected ){
This. ifselected = ifselected;
If (this. type = classlistitem. Group ){
If (! Ifselected)
This. defaultimagepath = imagedefalut_1;
Else
This. defaultimagepath = imagedefalut_2;
} Else
System. Out. println (iconstring );;
}
Public String tostring (){
Return this. Label + "";
}
Public String getdefaultimagepath (){
Return defaultimagepath;
}
Public void setdefaultimagepath (INT flag ){
If (flag = 1)
This. defaultimagepath = imagedefalut_1;
Else if (flag = 2)
This. defaultimagepath = imagedefalut_2;
Else
;
}
Public object getcontent (){
Return content;
}
Public void setcontent (Object content ){
This. content = content;
}
}