import com.nttdocomo.ui.*; import com.nttdocomo.util.*; import java.util.*; import java.io.*; import javax.microedition.io.*; import com.nttdocomo.io.*; // IApplicationクラス public class Bio extends IApplication { public void start(){ myCanvas ap = new myCanvas(this); Display.setCurrent(ap); } } class myCanvas extends Canvas { private IApplication iApp; int h,w,year,month,day,mode,sx,sy,cur,mv; int [] gx,gy; long btwn; String birth,work; int sin[] = {0,17,35,52,70,87,105,122,139,156,174,191,208,225,242,259,276,292,309,326, 342,358,375,391,407,423,438,454,469,485,500,515,530,545,559,574,588,602, 616,629,643,656,669,682,695,707,719,731,743,755,766,777,788,799,809,819, 829,839,848,857,866,875,883,891,899,906,914,921,927,934,940,946,951,956, 961,966,970,974,978,982,985,988,990,993,995,996,998,999,999,1000,1000 }; Font font; Image im; Calendar cal1,cal2; Date dt1,dt2; // コンストラクタメソッド myCanvas(IApplication ap) { super(); iApp = ap; setSoftLabel(Frame.SOFT_KEY_1, "タイトル"); setSoftLabel(Frame.SOFT_KEY_2, "終了"); try { MediaImage mi = MediaManager.getImage("resource:///bio.gif"); mi.use(); im = mi.getImage(); } catch (Exception e) {} // もしSO503i、D503iだったらSMALLを指定 String platform = System.getProperty("microedition.platform"); if(platform.equals("SO503i")||platform.equals("D503i")){ font = Font.getFont(Font.FACE_SYSTEM | Font.STYLE_PLAIN | Font.SIZE_SMALL ); }else{ font = Font.getDefaultFont(); } gx = new int[16]; gy = new int[16]; h = Display.getHeight(); w = Display.getWidth(); cal2 = Calendar.getInstance(); //誕生日,表示日 readData(); start(); } //初期化 public void start() { cal1 = Calendar.getInstance(); //今日 dt1 = cal1.getTime(); cur = 0; mode = 0; sy = 88; mv = 0; birth = ""; repaint(); } // 画面描画のためのメソッド public void paint(Graphics g) { int i,wg,y1,y2,y3,x1,x2,x3,x4,x5; long lng; Date dw; g.lock(); // 画面をロック if (mode == 0) { setBackground(g.getColorOfRGB(255,255,255)); g.clearRect(0,0,w,h); g.drawImage(im,(Display.getWidth()-100)/2,20); work = "あなたの生年月日は?"; sx = (w-font.stringWidth(work))/2; g.setColor(g.getColorOfRGB(0,0,0)); g.drawString(work,sx,sy-16); //メッセージ work = year + "/" + month +"/" + day; x1 = (w-font.stringWidth(work))/2; if (cur==0) { g.setColor(g.getColorOfRGB(255,0,0)); } else { g.setColor(g.getColorOfRGB(0,0,0)); } work = "" + year; g.drawString(work,x1,sy); //年 x2 = x1 + (font.stringWidth(work)); g.setColor(Graphics.WHITE); g.drawString("/",x2,sy); x3 = x2 + (font.stringWidth("/")); if (cur==1) { g.setColor(g.getColorOfRGB(255,0,0)); } else { g.setColor(g.getColorOfRGB(0,0,0)); } work = "" + month; g.drawString(work,x3,sy); //月 x4 = x3 + (font.stringWidth(work)); g.setColor(Graphics.WHITE); g.drawString("/",x4,sy); x5 = x4 + (font.stringWidth("/")); if (cur==2) { g.setColor(g.getColorOfRGB(255,0,0)); } else { g.setColor(g.getColorOfRGB(0,0,0)); } work = "" + day; g.drawString(work,x5,sy); //日 work = "ほぷしぃ"; sx = w-(font.stringWidth(work)); g.setColor(g.getColorOfRGB(0,0,0)); g.drawString(work,sx-9,h-15); //影 g.setColor(g.getColorOfRGB(0,255,0)); g.drawString(work,sx-10,h-15); //コピーライト } else if (mode==1) { g.clearRect(0,0,w,h); g.setColor(g.getColorOfRGB(0,0,0)); g.drawLine(0,h/2-8,w,h/2-8); work=cal1.get(Calendar.YEAR)+"/"+(cal1.get(Calendar.MONTH)+1)+"/"+cal1.get(Calendar.DATE); g.drawString(work,(w-font.stringWidth(work))/2,h); wg = w / 14; for (i=0;i<15;i++) { if (i==7) { g.setColor(g.getColorOfRGB(0,0,0)); } else { g.setColor(g.getColorOfRGB(120,120,120)); } g.drawLine(wg*i,0,wg*i,h-16); } y1 = calcGrf(btwn+mv,23); //身体 g.setColor(g.getColorOfRGB(255,0,0)); g.drawPolyline(gx,gy,16); y2 = calcGrf(btwn+mv,28); //感情 g.setColor(g.getColorOfRGB(0,255,0)); g.drawPolyline(gx,gy,16); y3 = calcGrf(btwn+mv,33); //知性 g.setColor(g.getColorOfRGB(0,0,255)); g.drawPolyline(gx,gy,16); g.setColor(g.getColorOfRGB(0,0,0)); g.drawString("身体",1,y1); g.drawString("感情",13,y2); g.drawString("知性",25,y3); g.setColor(g.getColorOfRGB(255,0,0)); g.drawString("身体",0,y1); g.setColor(g.getColorOfRGB(0,255,0)); g.drawString("感情",12,y2); g.setColor(g.getColorOfRGB(0,0,255)); g.drawString("知性",24,y3); } else if (mode==2) { g.clearRect(0,0,w,h); g.setColor(g.getColorOfRGB(0,0,0)); work=cal1.get(Calendar.YEAR)+"/"+(cal1.get(Calendar.MONTH)+1)+"/"+cal1.get(Calendar.DATE); g.drawString(work,(w-font.stringWidth(work))/2,16); i = (int)(btwn+mv)%23; if (i==0||i==11||i==12) { work="要注意日"; } else if (i>11) { work="停滞期"; } else { work="好調期"; } g.drawString("身体:"+work,10,48); i = (int)(btwn+mv)%28; if (i==0||i==14) { work="要注意日"; } else if (i>14) { work="停滞期"; } else { work="好調期"; } g.drawString("感情:"+work,10,64); i = (int)(btwn+mv)%33; if (i==0||i==16||i==17) { work="要注意日"; } else if (i>16) { work="停滞期"; } else { work="好調期"; } g.drawString("知性:"+work,10,80); } g.unlock(false); // ロック解除 } // イベント処理のためのメソッド public void processEvent(int type, int param){ long n; //ボタンが押された時 if(type == Display.KEY_PRESSED_EVENT){ work=""; if (param == Display.KEY_SOFT2){ writeData(); iApp.terminate(); } else if(param == Display.KEY_SOFT1){ start(); } else if(param == Display.KEY_SELECT){ if (mode==0) { if (chkDate()) { cal2.set(Calendar.YEAR ,year); cal2.set(Calendar.MONTH,month-1); cal2.set(Calendar.DATE,day); mode++; dt2 = cal2.getTime(); btwn = (dt1.getTime()-dt2.getTime())/(1000*3600*24); } } else if (mode==1) { mode++; } else if (mode==2) { mode--; } } else if(param == Display.KEY_LEFT){ if (cur>0 && mode==0) cur--; if (mode==1) { mv--; dt1 = cal1.getTime(); n = dt1.getTime()-24*3600*1000; dt1.setTime(n); cal1.setTime(dt1); } } else if(param == Display.KEY_RIGHT){ if (cur<2 && mode==0) cur++; if (mode==1) { mv++; dt1 = cal1.getTime(); n = dt1.getTime()+24*3600*1000; dt1.setTime(n); cal1.setTime(dt1); } } else if(param == Display.KEY_UP && mode==0){ if (cur==0) { if (year1900) year--; } else if (cur==1) { if (month>1) month--; } else if (cur==2) { if (day>1) day--; } } else if(param == Display.KEY_1){ work="1"; } else if(param == Display.KEY_2){ work="2"; } else if(param == Display.KEY_3){ work="3"; } else if(param == Display.KEY_4){ work="4"; } else if(param == Display.KEY_5){ work="5"; } else if(param == Display.KEY_6){ work="6"; } else if(param == Display.KEY_7){ work="7"; } else if(param == Display.KEY_8){ work="8"; } else if(param == Display.KEY_9){ work="9"; } else if(param == Display.KEY_0){ work="0"; } //数字キーが押された場合 if (work!="" && mode==0) { if (birth =="") { birth = work; } else { birth += work; } try { if (cur==0) { year = 1900 + Integer.parseInt(birth); } else if (cur==1) { month = Integer.parseInt(birth); } else if (cur==2) { day = Integer.parseInt(birth); } }catch(Exception e){} if (birth.length() == 2) birth = ""; } else { birth = ""; } } repaint(); } //角度からグラフの高さを返す public int calcSin( int sn ) { int rst=0; if ((sn>=0) && (sn<=90)){ rst = (-1)*sin[sn]; } else if ((sn>90) && (sn<=180)){ rst = (-1)*sin[180-sn]; } else if ((sn>180) && (sn<=270)){ rst = sin[sn-180]; } else if ((sn>270) && (sn<=359)){ rst = sin[360-sn]; } return rst*(h-16)/2000+(h-16)/2; } //日付、周期からグラフ描画配列を計算 public int calcGrf( long dt, int cyc ) { int i; for (i=-7;i<9;i++) { gx[i+7] = w / 15 * (i + 7); gy[i+7] = calcSin((int)((dt+i) % cyc)*360/cyc); } return gy[0]+8; } //日付の妥当性チェック public boolean chkDate() { if (month>12 || day>31) return false; if (day==31 && (month==4||month==6||month==9||month==11)) return false; if (day>=30 && month==2) return false; if (day==29 && month==2 && (year%4!=0 || year%100==0)) return false; return true; } // データ書き込みメソッド public void writeData() { int ii; OutputStream os = null; // OutputStreamの宣言 DataOutputStream dos = null; // InputStreamの宣言 try { // OutputStreamを取得する os = Connector.openOutputStream("scratchpad:///0;pos=0"); // 取得したOutputStreamを元にDataOutputStreamを作る dos = new DataOutputStream(os); // 値を書き出す dos.writeInt(year); dos.writeInt(month); dos.writeInt(day); // ストリームをフラッシュ dos.flush(); // ストリームを閉じる dos.close(); } catch(Exception e){ try { if (dos != null) dos.close(); } catch(Exception ex){} } } // データ読み込みメソッド public void readData() { InputStream is = null; // InputStreamの宣言 DataInputStream dis = null; // DataInputStreamの宣言 try { // InputStreamを取得する is = Connector.openInputStream("scratchpad:///0;pos=0"); // 取得したInputStreamを元にDataInputStreamを作る dis = new DataInputStream(is); // 値を読み込んで変数に入れていく year = dis.readInt(); month = dis.readInt(); day = dis.readInt(); // ストリームを閉じる dis.close(); } catch(Exception e){ try { if (dis != null) dis.close(); } catch(Exception ex){} } if (year == 0) { year = 1980; month = 1; day = 1; } } }