My first J2EE program: query the age based on the Chinese zodiac

Source: Internet
Author: User

Import java. Io. ioexception;
Import java. util. calendar;
Import javax. microedition. lcdui. Command;
Import javax. microedition. lcdui. commandlistener;
Import javax. microedition. lcdui. display;
Import javax. microedition. lcdui. displayable;
Import javax. microedition. lcdui. form;
Import javax. microedition. lcdui. image;
Import javax. microedition. lcdui. item;
Import javax. microedition. lcdui. List;
Import javax. microedition. lcdui. stringitem;
Import javax. microedition. lcdui. Ticker;
Import javax. microedition. MIDlet. MIDlet;
Import javax. microedition. MIDlet. midletstatechangeexception;

Public class medlet1 extends MIDlet implements commandlistener {

Private list lst = new list ("select the Chinese zodiac you want to query", list. Exclusive );
Private display DIS;
Private command cmd1 = new command ("OK", command. screen, 1 );
Private command cmd2 = new command ("return", command. screen, 1 );
Private command cmd3 = new command ("quit", command. Back, 1 );
Private form FRM = new form ("query result ");
Calendar c = calendar. getinstance ();
Private stringitem str1 = new stringitem ("", "", item. layout_left );
Private stringitem str2 = new stringitem ("","");
Private stringitem str3 = new stringitem ("","");
Private stringitem str4 = new stringitem ("","");
Private stringitem str5 = new stringitem ("","");
Private stringitem str6 = new stringitem ("","");
Private stringitem str7 = new stringitem ("","");
Private stringitem str8 = new stringitem ("","");
Private stringitem str9 = new stringitem ("","");
Public medlet1 (){
}
Protected void Startapp () throws midletstatechangeexception {
// Todo auto-generated method stub
Dis = display. getdisplay (this );
Dis. setcurrent (LST );
Image img1 = NULL;

Try {
Img1 = image. createimage ("/img1.png ");
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
 
 
Lst. append ("pig", null );
Lst. append ("e-dog", null );
Lst. append ("", null );
Lst. append ("monkey", null );
Lst. append ("Wuyang", null );
Lst. append ("Midday horse", null );
Lst. append ("snake", null );
Lst. append ("Chen long", null );
Lst. append ("rabbit", null );
Lst. append ("tiger", null );
Lst. append ("ugly cow", null );
Lst. append ("rat", null );

Lst. addcommand (cmd1 );
Lst. setticker (new ticker ("the function of this program is to query the age based on the Zodiac. Author: Gu Fang "));

FRM. addcommand (cmd2 );
FRM. addcommand (cmd3 );
 


FRM. setticker (new ticker ("the function of this program is to query the age based on the Zodiac. Author: Gu Fang "));
FRM. append (str1 );
FRM. append (str2 );
FRM. append (str3 );
FRM. append (str4 );
FRM. append (str5 );
FRM. append (str6 );
FRM. append (str7 );
FRM. append (str8 );

FRM. append (str9 );

FRM. append (img1 );
Lst. setcommandlistener (this );


}

Protected void destroyapp (Boolean arg0) throws midletstatechangeexception {
// Todo auto-generated method stub

}

Protected void pauseapp (){
// Todo auto-generated method stub

}
Public void commandaction (command arg0, displayable arg1 ){
Int jieguo, nianling;

String STR;

Jieguo = lst. getselectedindex ();
Nianling = jieguo + (C. Get (calendar. Year)-2008) + 1; // the serial number of the lst plus the difference between the current year and 2008 (08 years is the year of the mouse)
STR = string. valueof (nianling );
Dis. setcurrent (FRM );

FRM. setcommandlistener (this );

Str1.settext ("this Chinese zodiac this year" + STR + "");
Str2.settext (string. valueof (nianling + 12) + "");
Str3.settext (string. valueof (nianling + 24) + "");
Str4.settext (string. valueof (nianling + 36) + "");
Str5.settext (string. valueof (nianling + 48) + "");
Str6.settext (string. valueof (nianling + 60) + "");
Str7.settext (string. valueof (nianling + 72) + "");
Str8.settext (string. valueof (nianling + 84) + "");


If (arg0 = cmd2 ){

Dis. setcurrent (LST );
} Else if (arg0 = cmd3 ){
Yydestroyed ();
}

}

}
 

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.