The entire process of rapid development of j2-based jigsaw puzzle games (I)-display the best score

Source: Internet
Author: User

Code:

/*
* Created on 2004-6-20
*
* Todo to change the template for this generated file go
* Window-preferences-Java-code style-code templates
*/
Package cn.edu. xtu. tilepuzzle. UI;

Import javax. microedition. lcdui. Canvas;
Import javax. microedition. lcdui. Command;
Import javax. microedition. lcdui. commandlistener;
Import javax. microedition. lcdui. display;
Import javax. microedition. lcdui. displayable;
Import javax. microedition. lcdui. Font;
Import javax. microedition. lcdui. graphics;

Import cn.edu. xtu. tilepuzzle. gamedb;
Import cn.edu. xtu. tilepuzzle. contorler. mainuicontroller;
Import cn.edu. xtu. tilepuzzle. model. classpeopleinfo;
Import cn.edu. xtu. tilepuzzle. model. recordstoreoperations;

Public class showpeopleinfolistui extends canvas implements commandlistener {

Static final int lowcolor = 0x000000ff;
Static final int highcolor = 0x00ff0000;
Static final int highbgcolor = 0x00cccc;

Public int width;
Public int height;

Static final font fonttitle = gamedb. monospace_bold_large_font;
Static final Font font = gamedb. monospace_plain_medium_font;
Static final int lineheight = font. getheight ();
Private mainuicontroller;

Private command OK;
Private display;

Private int Startline = 0;
// Private int endline = 0;
Private int allpeopleline = 0;
Private int showlines = 16;

Private string titlestring [] = {"name", "name", "Hour "};

Private classpeopleinfo [];
Displayable;
Int xspace = 0;
Int lentitle [];
Int titleheight = 0;
// Private image titleimage;

Public showpeopleinfolistui (mainuicontroller, display, displayable ){
This. Display = display;
This. displayable = displayable;
This. mainuicontroller = mainuicontroller;
// This. setfullscreenmode (true );

This. width = getwidth ();
This. Height = getheight ();
// System. Out. println ("screen width, height:" + width + "," + height );

Startline = 0;
OK = new command ("return", command. OK, 0 );
Addcommand (OK );
Setcommandlistener (this );

}

Public void Init (){
// System. Out. println ("Get character information .... ");
This. classpeopleinfo = recordstoreoperations. readerrecordstores (gamedb. recordstorepeopleresult );
Allpeopleline = classpeopleinfo. length;
This. sortpeopleinfos ();

Startline = 0;
Lentitle = new int [3];

For (int ii = 0; II <3; II ++ ){
Lentitle [II] = font. stringwidth (titlestring [II]);
}
Xspace = (width-(lentitle [0] + lentitle [1] + lentitle [2])/4;

Titleheight = fonttitle. getheight ();

Showlines = (getheight ()-titleheight)/lineheight;
}

Protected void paint (Graphics g ){
// Todo auto-generated method stub

G. setcolor (255,255,190 );
G. fillrect (0, 0, width, height );

// System. Out. println ("screen width, height:" + width + "," + height );

G. setfont (fonttitle );
G. setcolor (50, 50, 50 );

Int Len [] = new int [3];
For (int ii = 0; II <3; II ++ ){
Len [II] = fonttitle. stringwidth (titlestring [II]);
}
G. drawstring (titlestring [0], xspace/6,
Lineheight/4, graphics. Left | graphics. Top );
G. drawstring (titlestring [1], xspace/5 + 2 * xspace + lentitle [0]-xspace/3,
Lineheight/4, graphics. Left | graphics. Top );
G. drawstring (titlestring [2], xspace/5 + 3 * xspace + lentitle [0] + lentitle [1],
Lineheight/4, graphics. Left | graphics. Top );
String STR [];
If (Startline + showlines> allpeopleline)
Showlines = allpeopleline-Startline;
For (INT I = Startline, j = 0; j <showlines; I ++, J ++ ){

G. setfont (font );
STR = getpeopleinfo (classpeopleinfo [I], I );
Len = new int [3];
For (int ii = 0; II <3; II ++ ){
Len [II] = font. stringwidth (STR [II]);
}

G. drawstring (STR [0], xspace/6,
Titleheight + J * lineheight + lineheight/4, graphics. Left | graphics. Top );
G. drawstring (STR [1], xspace/5 + 2 * xspace + lentitle [0]-xspace/3,
Titleheight + J * lineheight + lineheight/4, graphics. Left | graphics. Top );
G. drawstring (STR [2], xspace/5 + 3 * xspace + lentitle [0] + lentitle [1],
Titleheight + J * lineheight + lineheight/4, graphics. Left | graphics. Top );

// G. drawstring (mainmenu [I], (width-database. monospace_plain_medium_font.stringwidth (mainmenu [I])/2, startheight + (I * startheight * 3/2 + startheight/4), graphics. left | graphics. top );
}
}

Public String [] getpeopleinfo (classpeopleinfo, int I ){

String STR [] = new string [3];
STR [0] = formatstr0 (I );
STR [1] = classpeopleinfo. getname ();
STR [2] = classpeopleinfo. getstrtime ();
Return STR;
}

Public String formatstr0 (int I ){
If (1 + I)> 0 & (1 + I) <10)
Return "no." + "+ (1 + I) +" "+" name ";
Else if (1 + I) <100 & (1 + I)> = 10)
Return "no." + (1 + I) + "" + "name ";
Else
Return "no." + (1 + I) + "name ";
}

Public void sortpeopleinfos (){
Int Len = classpeopleinfo. length, I, j, flag;
// System. Out. println ("Total:" + Len );
Classpeopleinfo temp;
For (I = 0; I <len-1; I ++ ){
Temp = classpeopleinfo [I];
Flag = I;
For (j = I + 1; j <Len; j ++ ){
If (temp. Time> classpeopleinfo [J]. Time ){
// System. Out. println (temp. Time + "," + peopleinfo [J]. time );
Temp = classpeopleinfo [J];
Flag = J;
}
}
If (flag! = I ){
Classpeopleinfo [flag] = classpeopleinfo [I];
Classpeopleinfo [I] = temp;
}
}
// Return peopleinfo;
}

Protected void keypressed (INT code ){

If (getgameaction (CODE) = canvas. Up ){
If (Startline-1> = 0)
Startline --;
} Else if (getgameaction (CODE) = canvas. Down ){
If (Startline + showlines <allpeopleline)
Startline ++;
// Else
// Startline = 0;
} Else
;
// System. Out. println ("starting line:" + (Startline + 1) + "display line:" + showlines + "Total number:" + allpeopleline );
// System. Out. println ("menuidx =" + (menuidx) + ":" + mainmenu [menuidx]);
Repaint ();
}

Public void commandaction (command C, displayable dB ){
// Todo auto-generated method stub
If (C = OK ){
// System. Out. println ("Return ==== ");
Display. setcurrent (mainuicontroller. mainmenuui );
}
}
}

Run display

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.