java blog

          java boy

          常用鏈接

          統計

          最新評論

          靜夜思

           

          import javax.microedition.lcdui.*;
          import javax.microedition.midlet.*;


          public class GraphicsTest extends MIDlet{
            private Display display;

              public GraphicsTest() {
                  display=Display.getDisplay(this);

              }

              protected void destroyApp(boolean unconditional)  {


              }

              protected void pauseApp() {

              }

              protected void startApp(){
               MyCanvas mc=new MyCanvas();
               display.setCurrent(mc);
              }


          }
          class MyCanvas extends Canvas {

              public void paint(Graphics g){
               int width=getWidth();
               int height=getHeight();
          String a[]={"靜夜思","李白","床前明月光","疑是地上霜","舉頭望明月","低頭思故鄉"};
               g.setColor(0);
               g.fillRect(0, 0, width, height);

             
               g.setColor(0Xffff00);
               Font font=g.getFont();
               font=Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_UNDERLINED,Font.SIZE_LARGE);
               g.setFont(font);
               for(int i=0;i<a.length;i++){
                   g.drawString(a[i], 0, i*20,Graphics.LEFT|Graphics.BASELINE );
               }
             
              }

          }

           //--------------------------------------------------------------------------------------------
          利用移動原點坐標動起來之后的靜夜思

          import javax.microedition.lcdui.*;
          import javax.microedition.midlet.*;


          public class GraphicsTest extends MIDlet{
            private Display display;

              public GraphicsTest() {
                  display=Display.getDisplay(this);

              }

              protected void destroyApp(boolean unconditional)  {


              }

              protected void pauseApp() {

              }

              protected void startApp(){
               MyCanvas mc=new MyCanvas();
               display.setCurrent(mc);
              }


          }
          class MyCanvas extends Canvas {
          int aa=300;

          MyCanvas(){
          Walk w = new Walk();
            w.start();
          }
              public void paint(Graphics g){
               int width=getWidth();
               int height=getHeight();
          String a[]={"靜夜思","李白","床前明月光","疑是地上霜","舉頭望明月","低頭思故鄉"};
               g.setColor(0);
               g.fillRect(0, 0, width, height);


               g.setColor(0Xffff00);
               g.translate(80,aa);
               Font font=g.getFont();

               font=Font.getFont(Font.FACE_PROPORTIONAL,Font.FACE_SYSTEM,Font.SIZE_LARGE);
               g.setFont(font);
               for(int i=0;i<a.length;i++){
                   g.drawString(a[i], 0, i*20,20);
               }

              }


          class Walk extends Thread{

            public void run(){
             while(aa>80){
              aa--;
              repaint();
              try{
               sleep(50);
              }catch(Exception ee){}
             }
            }
           }

          }

          posted on 2009-12-01 20:25 javaz 閱讀(317) 評論(0)  編輯  收藏 所屬分類: javaME


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 庆安县| 建阳市| 新龙县| 张家口市| 萨迦县| 南京市| 化隆| 昭平县| 曲周县| 舒城县| 颍上县| 济源市| 阳山县| 神农架林区| 井冈山市| 泸定县| 奉新县| 福鼎市| 河津市| 琼中| 前郭尔| 格尔木市| 盈江县| 平塘县| 东乡县| 灵台县| 电白县| 沙河市| 宜良县| 博野县| 西和县| 汶上县| 新竹县| 满洲里市| 民乐县| 偏关县| 金华市| 昌宁县| 两当县| 临洮县| 离岛区|