예제 #1
0
  protected void paint(Graphics g) {

    g.setColor(COLOR_WHITE);
    g.fillRect(0, 0, getWidth(), getHeight());

    Font f1 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);
    Font f2 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);

    int px = getWidth() / 2;

    g.setColor(COLOR_BLUE);
    g.setFont(f1);
    g.drawString(
        Locale.getInst().getStr(Locale.SPLASH_TOP), px, 0, Graphics.TOP | Graphics.HCENTER);

    g.setFont(f2);
    g.drawString(
        Locale.getInst().getStr(Locale.SPLASH_BOTTOM),
        px,
        getHeight(),
        Graphics.BOTTOM | Graphics.HCENTER);

    if (logo != null) {
      g.drawImage(logo, getWidth() / 2, getHeight() / 2, Graphics.HCENTER | Graphics.VCENTER);
    }
  }
  protected void paint(Graphics g) {
    g.setColor(0xFAFAFA);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(0xDDDDDD);
    g.setStrokeStyle(Graphics.SOLID);
    g.drawLine(0, 0, getWidth(), 0);

    if (!pressedField) {
      g.setColor(0xE5E5E5);
    } else {
      pressedField = false;
      g.setColor(0xBCBCBC);
    }

    if (selected == Main.STATION_LIST_VIEW) {
      g.fillRect(0, 1, getWidth() / 2, getHeight() / 2);
    } else if (selected == Main.FAVORITE_LIST_VIEW) {
      g.fillRect(getWidth() / 2 + 1, 1, getWidth(), getHeight() / 2);
    } else if (selected == Main.MAP_SEARCH_VIEW) {
      g.fillRect(0, getHeight() / 2 + 1, getWidth() / 2, getHeight());
    } else if (selected == Main.GEOCODING_SEARCH_VIEW) {
      g.fillRect(getWidth() / 2 + 1, getHeight() / 2 + 1, getWidth(), getHeight());
    }

    g.setColor(0x000000);
    g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
    g.drawImage(imageStationListView, 60, 40, Graphics.HCENTER | Graphics.VCENTER);
    g.drawString(Main.STATION_LIST_VIEW_TITLE, 60, 80, Graphics.HCENTER | Graphics.TOP);
    g.drawImage(imageFavoriteListView, 180, 40, Graphics.HCENTER | Graphics.VCENTER);
    g.drawString(Main.FAVORITE_LIST_VIEW_TITLE, 180, 80, Graphics.HCENTER | Graphics.TOP);
    g.drawImage(imageMapSearchView, 60, 160, Graphics.HCENTER | Graphics.VCENTER);
    g.drawString(Main.MAP_SEARCH_VIEW_TITLE, 60, 200, Graphics.HCENTER | Graphics.TOP);
    g.drawImage(imageGeocodingSearchView, 180, 160, Graphics.HCENTER | Graphics.VCENTER);
    g.drawString(Main.GEOCODING_SEARCH_VIEW_TITLE, 180, 200, Graphics.HCENTER | Graphics.TOP);
  }
예제 #3
0
  protected void doPaintAxis(final Graphics g) {
    if (scaleSizeInPixel == 0 || mapBackground != null) {
      return;
    }

    final Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    g.setFont(font);
    g.setColor(0x00000000);

    final int textBottom = height - 4 - SCALE_HEIGTH;
    int left = 0;
    for (int i = 0; i < scaleConfiguration.labelLocation.length; i++) {
      final float location = scaleConfiguration.labelLocation[i];
      final float value = scaleConfiguration.labelValue[i];
      String label = Utils.floatToString(value, true);
      if (location == 0) {
        left = (font.stringWidth(label) / 2) + 2;
      } else if (location == 1) {
        label += " " + scaleConfiguration.unit;
      }
      g.drawString(
          label,
          left + (int) (scaleSizeInPixel * location),
          textBottom,
          Graphics.BOTTOM | Graphics.HCENTER);
    }
    g.drawRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel, SCALE_HEIGTH);
    g.fillRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel / 2, SCALE_HEIGTH);
  }
예제 #4
0
파일: LCD.java 프로젝트: 2cool/MobNav1
 public static void init(int MAX_X, int MAX_Y) {
   init = true;
   LCD.MAX_X = MAX_X;
   LCD.MAX_Y = MAX_Y;
   f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
   step_y = MAX_Y / 5;
   step_x = MAX_X >> 1;
 }
예제 #5
0
  protected void paint(Graphics g) {
    int width = this.getWidth();

    // Fill in the background White
    g.setColor(0xFFFFFF); // White
    g.fillRect(0, 0, width, this.getHeight());

    int y = yPos;
    y += MARGIN;

    if (this.logo != null) {
      g.drawImage(this.logo, width / 2, y, Graphics.TOP | Graphics.HCENTER);
      y += logo.getHeight() + MARGIN;
    }

    g.setColor(0x0); // Black

    // Write the title "About"
    final Font titleFont =
        Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD | Font.STYLE_UNDERLINED, Font.SIZE_LARGE);

    /*
     * TODO: currently paints ALL the text, even if there is (a lot) more
     * than can fit on the screen. (must do this first time to assess
     * 'height', but shouldn't need to do it for any other repaint
     */
    for (int i = 0; i < TITLES.length; i++) {
      final int basicFontHeight = DEFAULT_SIMPLE_FONT.getHeight();
      final int titleFontHeight = titleFont.getHeight();
      // Write out the 'message' heading
      g.setFont(titleFont);
      final String title = TITLES[i];
      int stringWidth = g.getFont().stringWidth(title);
      g.drawString(title, (width - stringWidth) / 2, y, 0);
      y += titleFontHeight;

      // Write out the 'message' text.
      g.setFont(DEFAULT_SIMPLE_FONT);
      for (int j = 0; j < this.formattedMessages[i].length; j++) {
        final String message = this.formattedMessages[i][j];
        stringWidth = g.getFont().stringWidth(message);
        g.drawString(message, (width - stringWidth) / 2, y, 0);
        y += basicFontHeight;
      }
      y += basicFontHeight;
    }

    // Set the total-Height the first time
    if (firstTime) {
      totalHeight = y + MARGIN;
      firstTime = false;
    }
  }
예제 #6
0
/** @author Makc */
public class MyToolsScreen extends Canvas {
  Vector myTools = new Vector();
  int se = 0;

  Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);

  /** constructor */
  public MyToolsScreen() {
    setFullScreenMode(true);
  }

  /** paint */
  public void paint(Graphics g) {
    g.setFont(MainCanvas.nameFont);

    g.setColor(255, 255, 255);
    g.fillRect(0, 0, getWidth(), getHeight());
    UIPainter.paintBackground(g);

    int i;
    for (i = 0; i < myTools.size(); i++) {
      if (se == i) {
        g.setColor(0, 0, 0);
        g.fillRect(
            0, i * MainCanvas.nameFont.getHeight(), getWidth(), MainCanvas.nameFont.getHeight());
        g.setColor(255, 255, 255);
        g.drawString(
            "" + JustPaint.c.brs[((Integer) myTools.elementAt(i)).intValue()],
            5,
            i * MainCanvas.nameFont.getHeight(),
            Graphics.LEFT | Graphics.TOP);
      } else {
        g.setColor(0, 0, 0);
        g.drawString(
            "" + JustPaint.c.brs[((Integer) myTools.elementAt(i)).intValue()],
            5,
            i * MainCanvas.nameFont.getHeight(),
            Graphics.LEFT | Graphics.TOP);
      }
    }

    UIPainter.paintLeftSoft(g, "Добавить");
    UIPainter.paintRightSoft(g, "Отмена");
  }

  /** Called when a key is pressed. */
  protected void keyPressed(int keyCode) {
    if ((keyCode == KEY_NUM2) || (keyCode == -1)) se--;
    if ((keyCode == KEY_NUM8) || (keyCode == -2)) se++;
    if (se < 0) se = myTools.size() - 1;
    if (se >= myTools.size()) se = 0;

    if ((keyCode == -5) || (keyCode == KEY_NUM5)) {
      JustPaint.c.brush = (((Integer) myTools.elementAt(se)).intValue());
      JustPaint.display.setCurrent(JustPaint.c);
    }

    // if (keyCode==KEY_NUM0) JustPaint.display.setCurrent(JustPaint.nf);
    if (keyCode == -6) {
      JustPaint.display.setCurrent(JustPaint.nmt);
    }

    if (keyCode == -7) {
      JustPaint.display.setCurrent(JustPaint.mm);
    }

    if (keyCode == -8) {
      myTools.removeElementAt(se);
      if (se >= myTools.size()) se--;
      if (se < 0) se = 0;
    }

    repaint();
  }
}
예제 #7
0
public class cCP {
  public static int SoundOn = 0;
  // #expand public static int SCR_W = %SCREENWIDTH%;
  public static int SCR_W = 240;
  // #expand public static int SCR_H = %SCREENHEIGHT%;
  public static int SCR_H = 320;
  // #expand public static final int FPSLIMIT = %FPSLIMIT%;
  public static final int FPSLIMIT = 10;
  public static final int FRAME_DT = 1000 / FPSLIMIT;
  public static boolean HasSound = true;
  // 图像资料定义
  public static final int IDX_BG = 0;
  public static final int IDX_BLUR1 = 1 + IDX_BG;
  public static final int IDX_BLUR2 = 1 + IDX_BLUR1;
  public static final int IDX_BLUR3 = 1 + IDX_BLUR2;
  public static final int IDX_CNM = 1 + IDX_BLUR3;
  public static final int IDX_CNM_2 = 1 + IDX_CNM;
  public static final int IDX_CNM_3 = 1 + IDX_CNM_2;
  public static final int IDX_CP = 1 + IDX_CNM_3;
  public static final int IDX_FIRSTLOGO = 1 + IDX_CP;
  public static final int IDX_GAME = 1 + IDX_FIRSTLOGO;
  public static final int IDX_LAST = 1 + IDX_GAME;
  public static final int IDX_LINE = 1 + IDX_LAST;
  public static final int IDX_NO = 1 + IDX_LINE;
  public static final int IDX_SOUND = 1 + IDX_NO;
  public static final int IDX_YES = 1 + IDX_SOUND;
  public static final int IDX_CPYL = 1 + IDX_YES;
  public static final int IDX_MAX = 1 + IDX_CPYL;
  public static Image[] Images = new Image[IDX_MAX];
  // 文件名,与IDX系列顺序相同
  public static final String[] Imgnames = {
    "/sp/bg.png",
    "/sp/blur1.png",
    "/sp/blur2.png",
    "/sp/blur3.png",
    "/sp/cnm.png",
    "/sp/cnm_2.png",
    "/sp/cnm_3.png",
    "/spg/cp.png",
    "/spg/firstlogo.png",
    "/spg/game.png",
    "/sp/last.png",
    "/sp/line.png",
    "/sp/no.png",
    "/sp/sound.png",
    "/sp/yes.png",
    "/spg/cp_yl.png",
  };

  private static final Image GetImage(int id) {
    Image retV = Images[id];
    try {
      if (retV == null) {
        retV = Images[id] = Image.createImage(Imgnames[id]);
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return retV;
  }

  private static final void FreeImage(int id) {
    Images[id] = null;
  }

  private static final void FreeAllImage() {
    for (int i = Images.length - 1; i >= 0; i--) Images[i] = null;
  }

  public static final void SetScreenSize(int w, int h) {
    SCR_W = w;
    SCR_H = h;
    // #if ENABLE_TOUCH=="TRUE"
    cTouch.SetScreenSize(w, h);
    // #endif
  }

  // public static boolean IsTigerOver = false;
  public static final void cCPdrawCleanScreen(Graphics g, int c) {
    g.setColor(c);
    g.fillRect(0, 0, SCR_W, SCR_H);
  }

  public cCP() {}
  /**
   * *************************************************************\ |** 老虎机 Tiger
   * \**************************************************************
   */
  // #if (TIGER=="TRUE")
  public static int runTime = 0;
  // #if SCREENWIDTH>=176
  public static int TIGER_DURING = 6000;
  // #else
  public static int TIGER_DURING = 6000;
  // #endif
  public static Image logo[];
  // #if SCREENWIDTH>=176
  public static final int[] PicIdx = {
    IDX_BG, IDX_CNM, IDX_CNM_2, IDX_CNM_3, IDX_BLUR2, IDX_BLUR3, IDX_BLUR1, IDX_CP, IDX_GAME
  };
  // #else
  public static final int[] PicIdx = {IDX_CNM, IDX_CP, IDX_GAME};
  // #endif
  public static boolean Tiger_Finished = false;

  public static Player SoundPlayer;
  // #endif
  public static void Tiger_Sound_Play() {
    // #if (TIGER=="TRUE")
    String tempName;
    tempName = "/sound/tiger.mid";
    InputStream isSound = Utils.getResourceAsStream(tempName);
    try {
      SoundPlayer = Manager.createPlayer(isSound, "audio/midi");
      isSound = null;
      SoundPlayer.realize();
      SoundPlayer.prefetch();
      SoundPlayer.setLoopCount(1);
      SoundPlayer.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
    // #endif
  }

  public static final void Tiger_Sound_Final() {
    // #if (TIGER=="TRUE")
    if (SoundPlayer != null) {
      if (SoundPlayer.getState() == Player.STARTED) {
        try {
          SoundPlayer.stop();
        } catch (Exception e) {
        }
      }
      SoundPlayer.deallocate();
      SoundPlayer.close();
      SoundPlayer = null;
    }
    ;
    // #endif
  }

  public static final boolean Tiger_Paint(Graphics g) {
    // #if !(TIGER=="TRUE")
    return true;
    // #else
    // #if SCREENWIDTH>=176
    return Tiger_Paint_Big(g);
    // #else
    return Tiger_Paint_Small(g);
    // #endif
    // #endif
  }

  private static final boolean Tiger_Paint_Small(Graphics g) {
    // #if !(TIGER=="TRUE")
    return true;
    // #else
    if (logo == null) {

      logo = new Image[PicIdx.length];
      for (int i = PicIdx.length - 1; i >= 0; i--) logo[i] = GetImage(PicIdx[i]);
      if (SoundOn != 0) Tiger_Sound_Play();
    }

    if (++runTime >= TIGER_DURING / FRAME_DT) {
      logo = null;
      FreeAllImage();
      // #if ENABLE_TOUCH=="TRUE"
      cTouch.ClearBtns();
      // #endif
      Tiger_Finished = true;
      Tiger_Sound_Final();
      return true;
    } else {
      cCPdrawCleanScreen(g, 0x0); // 清屏
      if (runTime < (TIGER_DURING / 3) / FRAME_DT) {
        g.drawImage(logo[0], (SCR_W >> 1), (SCR_H >> 1), Graphics.HCENTER | Graphics.VCENTER);
      } else if (runTime < (TIGER_DURING * 2 / 3) / FRAME_DT) {
        g.drawImage(logo[1], (SCR_W >> 1), (SCR_H >> 1), Graphics.HCENTER | Graphics.VCENTER);
      } else if (runTime < TIGER_DURING / FRAME_DT) {
        g.drawImage(logo[2], (SCR_W >> 1), (SCR_H >> 1), Graphics.HCENTER | Graphics.VCENTER);
      }
      return false;
    }
    // #endif
  }

  public static final boolean Tiger_Paint_Big(Graphics g) {
    // #if !(TIGER=="TRUE")
    return true;
    // #else
    if (logo == null) {
      logo = new Image[PicIdx.length];
      for (int i = PicIdx.length - 1; i >= 0; i--) logo[i] = GetImage(PicIdx[i]);
      if (SoundOn != 0) Tiger_Sound_Play();
    }
    if (++runTime >= TIGER_DURING / FRAME_DT) {
      // #if MODEL=="N73"
      if (SoundPlayer == null || SoundPlayer.getMediaTime() == 0) { // 不播放声音或者判断声音播放完毕时
        // #endif
        logo = null;
        FreeAllImage();
        // #if ENABLE_TOUCH=="TRUE"
        cTouch.ClearBtns();
        // #endif
        Tiger_Finished = true;
        Tiger_Sound_Final();
        return true;
        // #if MODEL=="N73"
      } else {
        return false;
      }
      // #endif
    } else {
      //			System.out.println("程序执行到此处");
      // cCPdrawCleanScreen(g, 0x0);//清屏
      g.drawImage(logo[0], SCR_W >> 1, SCR_H >> 1, Graphics.HCENTER | Graphics.VCENTER);

      if (runTime < (TIGER_DURING * 1 / 8) / FRAME_DT) {
        g.drawImage(
            logo[2], (SCR_W >> 1) - 2, (SCR_H >> 1) - 12, Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[1],
            (SCR_W >> 1) - logo[2].getWidth() - 2,
            (SCR_H >> 1) - 12,
            Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[3],
            (SCR_W >> 1) - 4 + logo[2].getWidth() + 2,
            (SCR_H >> 1) - 12 + 1,
            Graphics.HCENTER | Graphics.VCENTER);
      } else if (runTime < (TIGER_DURING * 2 / 8) / FRAME_DT) {
        g.drawImage(
            logo[4 + runTime % 3],
            SCR_W >> 1,
            (SCR_H >> 1) - 10,
            Graphics.HCENTER | Graphics.VCENTER);
      } else if (runTime < (TIGER_DURING * 3 / 8) / FRAME_DT) {
        g.drawImage(
            logo[4 + runTime % 3],
            SCR_W >> 1,
            (SCR_H >> 1) - 10,
            Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[4 + (runTime + 2) % 3],
            (SCR_W >> 1) - logo[2].getWidth() - 2,
            (SCR_H >> 1) - 10,
            Graphics.HCENTER | Graphics.VCENTER);
      } else if (runTime < (TIGER_DURING * 4 / 8) / FRAME_DT) {
        g.drawImage(
            logo[4 + runTime % 3],
            SCR_W >> 1,
            (SCR_H >> 1) - 10,
            Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[4 + (runTime + 2) % 3],
            (SCR_W >> 1) - logo[2].getWidth() - 2,
            (SCR_H >> 1) - 10,
            Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[4 + (runTime + 2) % 3],
            (SCR_W >> 1) + logo[2].getWidth(),
            (SCR_H >> 1) - 10,
            Graphics.HCENTER | Graphics.VCENTER);
      } else if (runTime < (TIGER_DURING * 5 / 8) / FRAME_DT) {
        g.drawImage(logo[1], SCR_W >> 1, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[4 + (runTime + 2) % 3],
            (SCR_W >> 1) - logo[2].getWidth() - 2,
            (SCR_H >> 1) - 10,
            Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[4 + (runTime + 2) % 3],
            (SCR_W >> 1) + logo[2].getWidth(),
            (SCR_H >> 1) - 10,
            Graphics.HCENTER | Graphics.VCENTER);
      } else if (runTime < (TIGER_DURING * 6 / 8) / FRAME_DT) {
        g.drawImage(logo[1], SCR_W >> 1, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[7],
            (SCR_W >> 1) + 1 - logo[2].getWidth() - 2,
            (SCR_H >> 1) - 12,
            Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[4 + (runTime + 2) % 3],
            (SCR_W >> 1) + logo[2].getWidth(),
            (SCR_H >> 1) - 10,
            Graphics.HCENTER | Graphics.VCENTER);
      } else if (runTime < (TIGER_DURING * 8 / 8) / FRAME_DT) {
        g.drawImage(logo[1], SCR_W >> 1, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[7],
            (SCR_W >> 1) + 1 - logo[2].getWidth() - 2,
            (SCR_H >> 1) - 12,
            Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(
            logo[8],
            (SCR_W >> 1) - 1 + logo[2].getWidth(),
            (SCR_H >> 1) - 12,
            Graphics.HCENTER | Graphics.VCENTER);
      }
      return false;
    }
    // #endif
  }

  public static final boolean Tiger_Update(int keycode) {
    // #if !(TIGER=="TRUE")
    return true;
    // #else
    return Tiger_Finished;
    // #endif
  }

  // 键值定义
  public static final int L = 0;
  public static final int R = 1 + L;
  public static int[] KeyValue = new int[] {DevConfig.KEY_LSK, DevConfig.KEY_RSK};
  /**
   * *************************************************************\ |** SoundOnOff 声音选项状态 *|
   * \**************************************************************
   */
  ////	#if SOUNDONOFF=="TRUE"
  public static final int LINESPACE = 3;
  /** 返回 true表示,本状态结束 */
  public static int SoundOnOffPaintCount = 0;

  public static int SoundOnOffTotalFrame = 30;
  public static boolean BtnSoundOnOffInited = false;
  public static boolean SoundOnOffisFinished = false;
  //// #endif
  public static final void SetKeyValue(int[] k) {
    //// #if SOUNDONOFF=="TRUE"
    KeyValue = k;
    //// #endif
  }

  public static final void SetHasSound(boolean On) {
    //// #if SOUNDONOFF=="TRUE"
    HasSound = On;
    //// #endif
  }

  public static final boolean SoundOnOff_paint(Graphics g) {
    // #if SCREENWIDTH<176 || MODEL=="D508" || MODEL=="KG90n" || MODEL=="D608"|| MODEL=="E398" ||
    // MODEL=="L7" || MODEL=="K1"|| MODEL=="S700"
    return SoundOnOff_paint_small(g);
    // #else
    return SoundOnOff_paint_big(g);
    // #endif
  }

  public static long TotalTime = 0;

  public static final boolean SoundOnOff_paint_small(Graphics g) {
    cCPdrawCleanScreen(g, 0);
    Image Img_firstLogo = GetImage(IDX_FIRSTLOGO);
    Image Img_CNM = GetImage(IDX_CNM);
    g.drawImage(
        Img_firstLogo,
        DevConfig.SCR_W >> 1,
        Img_firstLogo.getHeight() >> 1,
        Graphics.HCENTER | Graphics.VCENTER);
    g.drawImage(
        Img_CNM, cCP.SCR_W >> 1, Img_firstLogo.getHeight(), Graphics.HCENTER | Graphics.TOP);
    //		TotalTime += GLLib.s_Tick_Paint_FrameDT;

    if (TotalTime++ > 20) {
      GameMIDlet.SetSoundOnOff(false);
      return true;
    } else {
      return false;
    }
  }

  public static final boolean SoundOnOff_paint_big(Graphics g) {
    cCPdrawCleanScreen(g, 0);
    if (!BtnSoundOnOffInited) {
      // #if MODEL != "G12_Review"
      // #if ENABLE_TOUCH=="TRUE"
      cTouch.InitVirtualKeysForLRSK(SCR_W, SCR_H);
      // #endif
      // #endif
      BtnSoundOnOffInited = true;
    }
    int FontHeight = g.getFont().getHeight();
    if (!HasSound) {
      if ((++SoundOnOffPaintCount) > SoundOnOffTotalFrame) {
        FreeAllImage();
        // #if ENABLE_TOUCH=="TRUE"
        cTouch.ClearBtns();
        cTouch.TargetCanvas = null;
        // #endif
        SoundOnOffisFinished = true;
        return true;
      }
    }
    // 读取资源
    // #if SOUNDONOFF=="TRUE"
    Image Img_firstLogo = GetImage(IDX_FIRSTLOGO);
    // #endif
    Image Img_sound = GetImage(IDX_SOUND);
    Image Img_line = GetImage(IDX_LINE);
    Image Img_yes = GetImage(IDX_YES);
    Image Img_no = GetImage(IDX_NO);
    Image Img_cp = GetImage(IDX_CP);

    Image Img_CNM = GetImage(IDX_CNM);
    // #if CHANNEL_NAME=="SHYL"
    Image Img_CPYL = GetImage(IDX_CPYL);
    // #endif
    // 开始绘制
    int height = SCR_H;
    if (HasSound) {
      // 绘制左右软键
      g.drawImage(Img_yes, 0, height, Graphics.LEFT | Graphics.BOTTOM);
      g.drawImage(Img_no, SCR_W, height, Graphics.RIGHT | Graphics.BOTTOM);
      height -= Img_yes.getHeight();
      height -= LINESPACE;
      // 绘制线条
      height -= Img_line.getHeight();
      g.drawImage(Img_line, SCR_W >> 1, height, Graphics.HCENTER | Graphics.TOP);
      height -= LINESPACE;

      // 绘制  是否开启声音
      height -= Img_sound.getHeight();
      g.drawImage(Img_sound, SCR_W >> 1, height, Graphics.HCENTER | Graphics.TOP);
      height -= LINESPACE;
    }
    // #if CHANNEL_NAME=="SHYL"
    g.drawImage(Img_CPYL, SCR_W >> 1, height >> 1, Graphics.VCENTER | Graphics.HCENTER);
    // #endif
    // #if SOUNDONOFF=="TRUE"
    // #if LOGO=="TRUE"
    // 绘制CNM Logo
    height -= Img_CNM.getHeight();
    g.drawImage(Img_CNM, SCR_W >> 1, height, Graphics.HCENTER | Graphics.TOP);
    height -= LINESPACE;
    // #endif

    // 绘制  游戏 Logo
    // 这正是剩余的高度,将FirstLogo 放到正中
    g.drawImage(Img_firstLogo, SCR_W >> 1, height >> 1, Graphics.HCENTER | Graphics.VCENTER);
    // #endif
    // #if SHOWGAMENAME=="TRUE"
    // 画游戏名字
    // #endif
    return false;
  };
  /** 返回 true表示,本状态结束 */
  public static final boolean SoundOnOff_Update(int keycode) {

    //// #if SOUNDONOFF=="TRUE"
    int idx = -1;
    boolean retV = false;
    // #if SCREENWIDTH<176 || MODEL=="D508" || MODEL=="KG90n" || MODLE=="D608"|| MODEL=="E398" ||
    // MODEL=="L7"
    // #else
    if (!HasSound) {
      return SoundOnOffisFinished;
    }
    for (int i = KeyValue.length - 1; i >= 0; i--) {
      if (KeyValue[i] == keycode) {
        idx = i;
        break;
      }
    }
    if (idx < 0) return false;

    switch (idx) {
      case L:
        SoundOn = -1;

        GameMIDlet.SetSoundOnOff(true);

        retV = true;
        break;
      case R:
        SoundOn = 0;
        GameMIDlet.SetSoundOnOff(false);
        retV = true;
        break;
    }
    if (retV) {
      FreeAllImage();
      // #if ENABLE_TOUCH=="TRUE"
      cTouch.ClearBtns();
      // cTouch.TargetCanvas = null;
      // #endif
    }
    // #endif
    return retV;
    //// #else
    //		return true;
    //// #endif
  }
  // #if ENABLE_TOUCH=="TRUE"
  public static final void SoundOnOff_pointerPressed(int x, int y) {
    //// #if SOUNDONOFF=="TRUE"
    cTouch.pointerPressed(x, y);
    //// #endif
  }

  public static final void SoundOnOff_pointerReleased(int x, int y) {
    //// #if SOUNDONOFF=="TRUE"
    cTouch.pointerPressed(x, y);
    //// #endif
  }
  // #endif

  /**
   * ******************************************************************\ MoreGame QuitConfirm 部分
   * \*******************************************************************
   */
  public static String[] Info = null;

  public static String[] ConfirmInfo = null;
  // #expand	public static final String url_moreGame = "%URL_MOREGAME%" + "?" + "%CPID%" + "&" +
  // "%CONTENTID%";
  //	public static final String url_moreGame = "%URL_MOREGAME%";
  // #if SCREENWIDTH>=176
  public static Font MyFont = Font.getFont(Font.FACE_PROPORTIONAL, 0, Font.SIZE_SMALL);
  // #else
  public static Font MyFont = Font.getFont(Font.FACE_PROPORTIONAL, 0, Font.SIZE_LARGE);
  // #endif

  public static final boolean MoreGame_Paint(Graphics g) {
    if (GameMIDlet.GetInstance() != null) {
      GameMIDlet.GetInstance().notifyDestroyed();
      return true;
    }
    // #if MOREGAME=="TRUE" && MODEL!="D608" && MODEL!="D508"
    Image last = cCP.GetImage(IDX_LAST);
    if (Info == null) {
      // #if SCREENWIDTH>=176
      Info = new String[] {"更多精彩游戏", "尽在游戏频道", "Wap.xjoys.com", "确定", "退出"};
      // #else
      Info = new String[] {"更多精彩游戏", "尽在游戏频道", "Wap.xjoys.com", "确定", "退出"};
      // #endif
    }
    if (last != null) {
      g.drawImage(last, SCR_W >> 1, SCR_H >> 1, Graphics.VCENTER | Graphics.HCENTER);
    }
    if (Info != null) {
      g.setFont(MyFont);
      g.setColor(0xFFFFFF);
      /** 去掉 确定 退出 所占的2 */
      int ContextHeight = MyFont.getHeight() * ((Info.length - 2));
      int Y = (SCR_H - MyFont.getHeight() - ContextHeight) >> 1;
      int i = 0, loop_end = Info.length - 2;
      while (i < loop_end) {
        g.drawString(
            Info[i], SCR_W >> 1, Y + (i * MyFont.getHeight()), Graphics.HCENTER | Graphics.TOP);
        i++;
      }
      /** 左右软键,可以用宏,处理那些对调的机型,-3 为让基线下的文字显示出来 */
      g.drawString(Info[Info.length - 2], 0, SCR_H - 3, Graphics.LEFT | Graphics.BOTTOM);
      g.drawString(Info[Info.length - 1], SCR_W, SCR_H - 3, Graphics.RIGHT | Graphics.BOTTOM);
    }
    return false;
    // #else
    return true;
    // #endif
  }

  public static final boolean QuitConfirm_Paint(Graphics g) {
    //		Image last = cCP.GetImage(IDX_LAST);
    if (ConfirmInfo == null) {
      // #if SCREENWIDTH>=176
      ConfirmInfo = new String[] {"确定退出?", "确定", "返回"};
      // #else
      ConfirmInfo = new String[] {"确定退出?", "确定", "返回"};
      // #endif
    }
    //		if (last!=null)
    //		{
    //			g.drawImage(last,SCR_W>>1,SCR_H>>1,Graphics.VCENTER|Graphics.HCENTER);
    //		}
    if (ConfirmInfo != null) {
      g.setColor(0x000000);
      g.fillRect(0, 0, SCR_W, SCR_H);
      g.setColor(0xffffff);
      /** 去掉 确定 退出 所占的2 */
      int ContextHeight = MyFont.getHeight() * ((ConfirmInfo.length - 2));
      int Y = (SCR_H - MyFont.getHeight() - ContextHeight) >> 1;
      int i = 0, loop_end = ConfirmInfo.length - 2;
      while (i < loop_end) {
        g.drawString(
            ConfirmInfo[i],
            SCR_W >> 1,
            Y + (i * MyFont.getHeight()),
            Graphics.HCENTER | Graphics.TOP);
        i++;
      }
      /** 左右软键,可以用宏,处理那些对调的机型,-3 为让基线下的文字显示出来 */
      g.drawString(
          ConfirmInfo[ConfirmInfo.length - 2], 0, SCR_H - 3, Graphics.LEFT | Graphics.BOTTOM);
      g.drawString(
          ConfirmInfo[ConfirmInfo.length - 1], SCR_W, SCR_H - 3, Graphics.RIGHT | Graphics.BOTTOM);
    }
    return false;
  }

  public static final int MOREGAME_NULL = 0;
  public static final int MOREGAME_OPENED = 1;
  public static final int MOREGAME_CANCEL = 2;

  public static final int MoreGame_Update(MIDlet midlet, int keycode) {
    // #if MOREGAME=="TRUE" && MODEL!="D608" && MODEL!="D508"
    int idx = -1;
    int retV = MOREGAME_NULL;
    for (int i = KeyValue.length - 1; i >= 0; i--) {
      if (KeyValue[i] == keycode) {
        idx = i;
        break;
      }
    }
    if (idx < 0) return MOREGAME_NULL;

    switch (idx) {
      case L:
        MoreGame_DoOpen(midlet);
        retV = MOREGAME_OPENED;
        break;
      case R:
        retV = MOREGAME_CANCEL;
        break;
    }
    if (retV != MOREGAME_NULL) {
      FreeAllImage();
      // #if ENABLE_TOUCH=="TRUE"
      cTouch.ClearBtns();
      // #endif
    }
    return retV;
    // #else
    return MOREGAME_CANCEL;
    // #endif
  }

  public static final int QuitConfirm_Update(int keycode) {
    int idx = -1;
    int retV = MOREGAME_NULL;
    for (int i = KeyValue.length - 1; i >= 0; i--) {
      if (KeyValue[i] == keycode) {
        idx = i;
        break;
      }
    }
    if (idx < 0) return MOREGAME_NULL;

    switch (idx) {
      case L:
        // MoreGame_DoOpen(midlet);
        retV = MOREGAME_CANCEL;
        GameMIDlet.GetInstance().notifyDestroyed();
        break;
      case R:
        retV = MOREGAME_NULL;
        break;
    }
    if (retV != MOREGAME_NULL) {
      FreeAllImage();
      // #if ENABLE_TOUCH=="TRUE"
      cTouch.ClearBtns();
      // #endif
    }
    return retV;
  }

  private static final void MoreGame_DoOpen(MIDlet midlet) {
    try {
      midlet.platformRequest(url_moreGame);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public static final int PAUSE_NULL = 0;
  public static final int PAUSE_OPENED = 1;
  public static final int PAUSE_CANCEL = 2;

  public static final boolean Pause_Paint(Graphics g) {
    return false;
  }

  public static final int Pause_Update(int keyCode) {
    switch (keyCode) {
      case DevConfig.KEY_LSK:
        return PAUSE_OPENED;
      case DevConfig.KEY_RSK:
        return PAUSE_CANCEL;
      default:
        return PAUSE_NULL;
    }
  }

  public static int Paint_Index = 0;
  /** 区别黑字白字 用法:H>>6黑字 H原值白字 */
  public static final void String_Splash_Paint(Graphics g, String str, int W, int H) {
    if (Paint_Index++ % 10 < 5) {
      if (H > 1000) { // 区别黑字白字
        g.setColor(0x000000);
        g.drawString(str, W >> 1, H >> 7, Graphics.TOP | Graphics.HCENTER);
      } else {
        g.setColor(0xFFFFFF);
        g.drawString(str, W >> 1, H >> 1, Graphics.TOP | Graphics.HCENTER);
      }
    }
  }

  public static String[] SugInfo = null;
  public static int SugRunTime = 0;
  /**
   * 教育类提示屏
   *
   * @param g
   * @param str
   * @return
   */
  //	//#if SCREENWIDTH>=176
  //	public static int totaltime = 50;
  //	//#else
  //	public static int totaltime = 100;
  //	//#endif
  //	public static boolean SuggestionPaint(Graphics g,String[] str){
  //// #if REVIEW!="FALSE"
  //		if(SugRunTime++>totaltime){
  //			return true;
  //		}
  //		if(SugInfo == null){
  //			SugInfo = str;
  //		}
  //		//#if SCREENWIDTH>=176
  //		if(SugInfo != null){
  //			g.setColor(0, 0, 0);
  //			g.fillRect(0, 0, SCR_W, SCR_H);
  //			//#if SCREENWIDTH<176
  //			g.setFont(MyFont);
  //			//#endif
  //			g.setColor(0xFFFFFF);
  //			/** 去掉  确定 退出 所占的2 */
  //			int ContextHeight = MyFont.getHeight() * ((SugInfo.length));
  //			int Y = (SCR_H - MyFont.getHeight() - ContextHeight)>> 1;
  //			int i = 0,loop_end = SugInfo.length;
  //			while (i<loop_end)
  //			{
  //				g.drawString(SugInfo[i], SCR_W>>1, Y + (i*MyFont.getHeight()),
  // Graphics.HCENTER|Graphics.TOP);
  //				i++;
  //			}
  //		}
  //		//#else
  //		if(SugInfo != null){
  //			g.setColor(0, 0, 0);
  //			g.fillRect(0, 0, SCR_W, SCR_H);
  //			//#if SCREENWIDTH<176
  //			g.setFont(MyFont);
  //			//#endif
  //			g.setColor(0xFFFFFF);
  //			/** 去掉  确定 退出 所占的2 */
  //			int ContextHeight = MyFont.getHeight() * ((SugInfo.length>>1));
  //			int Y = (SCR_H - MyFont.getHeight() - ContextHeight)>> 1;
  //			int i = 0,loop_end = SugInfo.length>>1;
  //			if(SugRunTime<=(totaltime>>1)){
  //				while (i<loop_end)
  //				{
  //					g.drawString(SugInfo[i], SCR_W>>1, Y + (i*MyFont.getHeight()),
  // Graphics.HCENTER|Graphics.TOP);
  //					i++;
  //				}
  //			}else{
  //				while (i<loop_end)
  //				{
  //					g.drawString(SugInfo[i+(SugInfo.length>>1)], SCR_W>>1, Y + (i*MyFont.getHeight()),
  // Graphics.HCENTER|Graphics.TOP);
  //					i++;
  //				}
  //			}
  //		}
  //		//#endif
  //		return false;
  //// #else
  //		return true;
  //// #endif
  //
  //	}
  // #if SCREENWIDTH>=176
  public static int totaltime = 50;
  // #else
  public static int totaltime = 100;
  // #endif
  public static boolean SuggestionPaint(Graphics g, String[] str) {
    // #if REVIEW=="FALSE" && EDUCATION =="TRUE"
    if (SugRunTime++ > totaltime) {
      return true;
    }
    if (SugInfo == null) {
      SugInfo = str;
    }
    // #if SCREENWIDTH>=176
    if (SugInfo != null) {
      g.setColor(0, 0, 0);
      g.fillRect(0, 0, SCR_W, SCR_H);
      // #if SCREENWIDTH<176
      g.setFont(MyFont);
      // #endif
      g.setColor(0xFFFFFF);
      /** 去掉 确定 退出 所占的2 */
      int ContextHeight = MyFont.getHeight() * ((SugInfo.length));
      int Y = (SCR_H - MyFont.getHeight() - ContextHeight) >> 1;
      int i = 0, loop_end = SugInfo.length;
      while (i < loop_end) {
        g.drawString(
            SugInfo[i], SCR_W >> 1, Y + (i * MyFont.getHeight()), Graphics.HCENTER | Graphics.TOP);
        i++;
      }
    }
    // #else
    if (SugInfo != null) {
      g.setColor(0, 0, 0);
      g.fillRect(0, 0, SCR_W, SCR_H);
      // #if SCREENWIDTH<176
      g.setFont(MyFont);
      // #endif
      g.setColor(0xFFFFFF);
      /** 去掉 确定 退出 所占的2 */
      int ContextHeight = MyFont.getHeight() * ((SugInfo.length >> 1));
      int Y = (SCR_H - MyFont.getHeight() - ContextHeight) >> 1;
      int i = 0, loop_end = SugInfo.length >> 1;
      if (SugRunTime <= (totaltime >> 1)) {
        while (i <= loop_end) {
          g.drawString(
              SugInfo[i],
              SCR_W >> 1,
              Y + (i * MyFont.getHeight()),
              Graphics.HCENTER | Graphics.TOP);
          i++;
        }
      } else {
        while (i < loop_end) {
          g.drawString(
              SugInfo[i + (SugInfo.length >> 1) + 1],
              SCR_W >> 1,
              Y + (i * MyFont.getHeight()),
              Graphics.HCENTER | Graphics.TOP);
          i++;
        }
      }
    }
    // #endif
    return false;
    // #else
    return true;
    // #endif

  }
};
예제 #8
0
 public void setFont(int size) {
   Font font = Font.getFont(Font.FACE_SYSTEM, 0, size);
   g.setFont(font);
 }
예제 #9
0
파일: LCD.java 프로젝트: 2cool/MobNav1
  public void paint(Graphics g) {

    if (init == false) init(MyCanvas.max_x, MyCanvas.max_y);

    g.setFont(f);
    g.setColor(0xffffff);
    g.fillRect(0, 0, MAX_X, MAX_Y);

    drawSpeed(g, 0, 0, (GGA.fixQuality != 0) ? BTGPS.speed4A() * 3.6 : -1);

    /////// 1
    Time time;
    if (BTGPS.isOn()) {
      time = NMEA.time;
    } else {
      Date date = new Date();
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(date);
      double dtime = 3600 * calendar.get(Calendar.HOUR_OF_DAY);
      dtime += 60 * calendar.get(Calendar.MINUTE);
      dtime += calendar.get(Calendar.SECOND);
      dtime *= 1000;
      time = new Time(dtime);
    }
    drawTime(g, 1, 0, time, true, false);
    // 2
    time = new Time(BTGPS.moving_timeMsec());
    drawTime(g, 0, 1, time, false, true);

    // 3
    time = new Time(BTGPS.stoped_timeMsec());
    drawTime(g, 0, 2, time, false, true);
    // 4
    double odom = BTGPS.getDistance();
    drawDist(g, 0, 3, odom);
    drawSpeed(g, 1, 1, (GGA.fixQuality != 0) ? BTGPS.averageSpeed() * 3.6 : -1);

    g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
    g.setColor(0);
    g.drawString("Speed", 4, 0, 0); // 00
    g.drawString("Time", (MAX_X >> 1) + 4, 0, 0); // 10
    g.drawString("Moving Time", 4, step_y, 0); // 01
    g.drawString("Stoped", 4, step_y + step_y, 0); // 02
    g.drawString("Trip Odom", 4, step_y * 3, 0); // 03
    g.drawString("Moving Avg", (MAX_X >> 1) + 4, step_y, 0); // 03
    g.setColor(0x777777);

    g.fillRect((MAX_X >> 1) - 1, 0, 2, MAX_Y);
    for (int y = step_y - 1; y < MAX_Y - step_y; y += step_y) g.fillRect(0, y - 1, MAX_X, 2);

    //	int x=(MAX_X>>1)+(((MAX_X>>1)-(4*24+6))>>1);
    // g.drawString(time.get(":"),x,y,0);

    // drawTime(g,1,2,BTGPS.moving_time*0.001);//BTGPS.nmea.time.msec()*0.001);

    // drawDigit(g, 0, 24, '8', true);
    // drawDigit(g, 24, 24, '8', false);

    // if (BTGPS.isOn()==false)
    // synchronized(MyCanvas.update){
    //   MyCanvas.update.notify();
    //   }

  }
예제 #10
0
/** 游戏地图,地图高16个小砖块,宽16小砖块,但是游戏容器高16,宽12(包括左右2堵墙) 所以容器的内直径为10 */
public class KetrisMap {

  // 地图数据
  protected int mapdata[][];
  protected boolean mapBlockExist[]; // 长度为16的boolean数组,如果mapBlockExist[i]=true,则第i+1行有砖块
  private int score; // 分数
  public static final Font SCOREFONT =
      Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);

  public KetrisMap() {
    mapdata = new int[16][12];
    mapBlockExist = new boolean[16];
  }

  public void init() {
    // 清除计分
    score = 0;
    // 先把全部元素清0
    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 12; j++) {
        mapdata[i][j] = 0;
      }
      mapBlockExist[i] = false;
    }

    // 设置2堵墙
    for (int i = 0; i < 16; i++) {
      mapdata[i][0] = 8;
      mapdata[i][11] = 8;
    }

    // 设置容器底
    for (int i = 0; i < 12; i++) {
      mapdata[15][i] = 8;
    }

    mapBlockExist[15] = true;
  }

  /**
   * 获取地图某行某列的数据
   *
   * @param x int 行号
   * @param y int 列号
   * @return int 地图数据,非0表示有砖块
   */
  public int get(int x, int y) {
    int data = mapdata[y][x];

    return data;
  }

  /* 设置地图数据 */
  public void set(int x, int y, int val) {
    if (x >= 0 && y >= 0) {
      mapdata[y][x] = val;
      mapBlockExist[y] = true;
    }
  }

  /**
   * 该方法其实只负责非运动砖块
   *
   * @param g Graphics
   */
  public void paint(Graphics g) {
    // 清屏
    KetrisCanvas.clear(g);

    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 12; j++) {
        if (mapdata[i][j] == 8) {
          KetrisBlock.drawBrick(
              KetrisCanvas.GAMEAREA_X + j * KetrisCanvas.BRICK_WIDTH,
              KetrisCanvas.GAMEAREA_Y + i * KetrisCanvas.BRICK_WIDTH,
              g,
              7);
        }
      }
    }
  }

  public boolean check(Graphics g, int row) {
    boolean deleteFlag = false;

    // 最多可以连消4行
    int tmpRowNo;
    if (row + 4 >= 15) {
      tmpRowNo = 15;
    } else {
      tmpRowNo = row + 4;
    }

    for (int y = row; y < tmpRowNo; y++) {
      boolean flag = true;

      for (int x = 1; x < 11; x++) {
        if (mapdata[y][x] == 0) {
            /* 空白区 */
          flag = false;
        }
      }

      /* 需要消行 */
      if (flag) {
        mapBlockExist[y] = false;
        for (int x = 1; x < 11; x++) {
          mapdata[y][x] = 0;
        }

        deleteRow(g, y);

        deleteFlag = true;
        // 加分
        score += 10;
        paintScore(g);
        // 发声
        // try {
        // if (player != null) {
        // player.start();
        // }
        //
        // // }
        // catch (MediaException me) {
        // System.out.println("sound not availible");
        // }

      }
    }

    return deleteFlag;
  }

  // 删除行,只是简单的把该行置黑
  protected void deleteRow(Graphics g, int y) {
    g.setColor(KetrisCanvas.BACKGROUD);
    g.fillRect(
        KetrisCanvas.GAMEAREA_X + KetrisCanvas.BRICK_WIDTH,
        KetrisCanvas.GAMEAREA_Y + y * KetrisCanvas.BRICK_WIDTH,
        10 * KetrisCanvas.BRICK_WIDTH,
        KetrisCanvas.BRICK_WIDTH);
  }

  /* 该方法在有消去行为后调用 */
  public void repaintMap(Graphics g) {
    // 从容启底开始
    for (int i = 14; i > 0; i--) {
      int tmp;

      // 有砖块的行才移动
      if (mapBlockExist[i]) {
        // 只有下一行为空白行才进行移动
        if (!mapBlockExist[i + 1]) {
          tmp = i + 1;

          if (!mapBlockExist[i + 2]) {
            tmp = i + 2;

            if (!mapBlockExist[i + 3]) {
              tmp = i + 3;
            }
          }
          deleteRow(g, i);
          // 行复制
          for (int j = 1; j < 11; j++) {
            mapdata[tmp][j] = mapdata[i][j];
            mapdata[i][j] = 0;
          }
          mapBlockExist[i] = false;
          mapBlockExist[tmp] = true;

          drawBlock(g, tmp);
        }
      }
    }
  }

  public void drawBlock(Graphics g, int y) {
    for (int x = 1; x < 11; x++) {
      if (mapdata[y][x] != 0) {
        KetrisBlock.drawBrick(
            KetrisCanvas.GAMEAREA_X + x * KetrisCanvas.BRICK_WIDTH,
            KetrisCanvas.GAMEAREA_Y + y * KetrisCanvas.BRICK_WIDTH,
            g,
            mapdata[y][x] - 1);
      }
    }
  }

  private void paintScore(Graphics g) {
    // 清除记分牌
    g.setColor(KetrisCanvas.BACKGROUD);
    g.fillRect(
        KetrisCanvas.GAMEAREA_X + 12 * KetrisCanvas.BRICK_WIDTH,
        KetrisCanvas.GAMEAREA_Y + 6 * KetrisCanvas.BRICK_WIDTH,
        KetrisCanvas.BRICK_WIDTH * 4,
        KetrisCanvas.BRICK_WIDTH * 4);
    // 计分
    g.setColor(0, 255, 0);
    g.setFont(SCOREFONT);
    g.drawString(
        "" + score,
        KetrisCanvas.GAMEAREA_X + 14 * KetrisCanvas.BRICK_WIDTH,
        KetrisCanvas.GAMEAREA_Y + 8 * KetrisCanvas.BRICK_WIDTH,
        Graphics.BASELINE | Graphics.HCENTER);
  }
}
예제 #11
0
 public CatcherCanvas(IViewNavigator viewNavigator) {
   this.viewNavigator = viewNavigator;
   menu = new Menu(globalItems);
   sysFont = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
 }
예제 #12
0
  /**
   * Deserializes an object from the given stream.
   *
   * @param in the data input stream, from which the object is deserialized
   * @return the serializable object
   * @throws IOException when serialization data could not be read or the Serializable class could
   *     not get instantiated
   */
  public static Object deserialize(DataInputStream in) throws IOException {
    byte version = in.readByte();
    // #if polish.debug.warn
    if (version > VERSION) {
      // #debug warn
      System.out.println(
          "Warning: trying to deserialize class that has been serialized with a newer version ("
              + version
              + ">"
              + VERSION
              + ").");
    }
    // #endif
    boolean isNull = in.readBoolean();
    if (isNull) {
      return null;
    }
    byte type = in.readByte();
    switch (type) {
      case TYPE_EXTERNALIZABLE:
        String className = in.readUTF();
        // #if polish.JavaSE
        if (obfuscationDeserializeMap != null) {
          String fullClassName = (String) obfuscationDeserializeMap.get(className);
          if (fullClassName != null) {
            // System.out.println("Serializer.deserialize: translating classname from " + className
            // + " to " +  fullClassName );
            className = fullClassName;
          }
        }
        // #endif
        // #debug debug
        // #= System.out.println("deserialize " + className + "...");
        Externalizable extern = null;
        try {
          extern = (Externalizable) Class.forName(className).newInstance();
        } catch (Exception e) {
          // #debug error
          System.out.println("Unable to instantiate serializable \"" + className + "\"" + e);
          throw new IOException(e.toString());
        }
        extern.read(in);
        return extern;
      case TYPE_EXTERNALIZABLE_ARRAY:
        String cn = in.readUTF();
        // #if polish.JavaSE
        if (obfuscationDeserializeMap != null) {
          String fullClassName = (String) obfuscationDeserializeMap.get(cn);
          if (fullClassName != null) {
            // System.out.println("Serializer.deserialize: translating classname from " + cn + " to
            // " +  fullClassName );
            cn = fullClassName;
          }
        }
        // #endif

        int length = in.readInt();
        Externalizable[] externalizables;

        // #if !polish.JavaSE
        externalizables = new Externalizable[length];
        // #else
        try {
          // #if false
          externalizables = null;
          // #else
          // # externalizables = (Externalizable[]) Array.newInstance(Class.forName( cn ), length);
          // #endif
        } catch (Exception e) {
          // #debug error
          System.out.println("Unable to instantiate Serializable \"" + cn + "\"" + e);
          throw new IOException(e.toString());
        }
        // #endif

        Class[] classes = new Class[Math.min(length, 7)];
        Class currentClass;
        byte idCounter = 0;
        for (int i = 0; i < externalizables.length; i++) {
          int classId = in.readByte();
          if (classId == 0) { // new class name
            className = in.readUTF();
            // #if polish.JavaSE
            if (obfuscationDeserializeMap != null) {
              String fullClassName = (String) obfuscationDeserializeMap.get(className);
              if (fullClassName != null) {
                // System.out.println("Serializer.deserialize: translating classname from " +
                // className + " to " +  fullClassName );
                className = fullClassName;
              }
            }
            // #endif
            try {
              currentClass = Class.forName(className);
            } catch (ClassNotFoundException e) {
              // #debug error
              System.out.println("Unable to load Serializable class \"" + className + "\"" + e);
              throw new IOException(e.toString());
            }
            if (idCounter > classes.length) {
              Class[] newClasses = new Class[classes.length + 7];
              System.arraycopy(classes, 0, newClasses, 0, classes.length);
              classes = newClasses;
            }
            classes[idCounter] = currentClass;
            idCounter++;
          } else {
            currentClass = classes[classId - 1];
          }
          Externalizable externalizable;
          try {
            externalizable = (Externalizable) currentClass.newInstance();
            externalizable.read(in);
            externalizables[i] = externalizable;
          } catch (Exception e) {
            // #debug error
            System.out.println(
                "Unable to instantiate Serializable \"" + currentClass.getName() + "\"" + e);
            throw new IOException(e.toString());
          }
        }
        return externalizables;
      case TYPE_OBJECT_ARRAY:
        length = in.readInt();
        Object[] objects = new Object[length];
        for (int i = 0; i < objects.length; i++) {
          objects[i] = deserialize(in);
        }
        return objects;
      case TYPE_BYTE:
        return new Byte(in.readByte());
      case TYPE_SHORT:
        return new Short(in.readShort());
      case TYPE_INTEGER:
        return new Integer(in.readInt());
      case TYPE_LONG:
        return new Long(in.readLong());
        // #if polish.hasFloatingPoint
      case TYPE_FLOAT:
        return new Float(in.readFloat());
      case TYPE_DOUBLE:
        return new Double(in.readDouble());
        // #endif
      case TYPE_STRING:
        return in.readUTF();
      case TYPE_STRING_BUFFER:
        return new StringBuffer(in.readUTF());
      case TYPE_CHARACTER:
        return new Character(in.readChar());
      case TYPE_BOOLEAN:
        return new Boolean(in.readBoolean());
      case TYPE_DATE:
        return new Date(in.readLong());
      case TYPE_CALENDAR:
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(in.readLong()));
        return calendar;
      case TYPE_RANDOM:
        return new Random();
      case TYPE_HASHTABLE:
        int size = in.readInt();
        Hashtable hashtable = new Hashtable(size);
        for (int i = 0; i < size; i++) {
          Object key = deserialize(in);
          Object value = deserialize(in);
          hashtable.put(key, value);
        }
        return hashtable;
      case TYPE_STACK:
      case TYPE_VECTOR:
        size = in.readInt();
        Vector vector;
        if (type == TYPE_STACK) {
          vector = new Stack();
        } else {
          vector = new Vector(size);
        }
        for (int i = 0; i < size; i++) {
          Object value = deserialize(in);
          vector.addElement(value);
        }
        return vector;
        // #if polish.midp2
      case TYPE_IMAGE:
        byte subType = in.readByte();
        if (subType == TYPE_IMAGE_RGB) {
          int width = in.readInt();
          int height = in.readInt();
          int[] rgb = new int[width * height];
          for (int i = 0; i < rgb.length; i++) {
            rgb[i] = in.readInt();
          }
          return Image.createRGBImage(rgb, width, height, true);
        }

        // this is a bytes based format like png:
        int bytesLength = in.readInt();
        byte[] buffer = new byte[bytesLength];
        in.readFully(buffer);
        return Image.createImage(buffer, 0, bytesLength);
        // #endif
        // #if polish.midp
      case TYPE_FONT:
        int face = in.readInt();
        int style = in.readInt();
        size = in.readInt();
        return Font.getFont(face, style, size);
      case TYPE_COMMAND:
        int cmdType = in.readInt();
        int priority = in.readInt();
        String label = in.readUTF();
        return new Command(label, cmdType, priority);
        // #endif
      case TYPE_BYTE_ARRAY:
        length = in.readInt();
        byte[] byteNumbers = new byte[length];
        in.readFully(byteNumbers);
        return byteNumbers;
      case TYPE_SHORT_ARRAY:
        length = in.readInt();
        short[] shortNumbers = new short[length];
        for (int i = 0; i < length; i++) {
          shortNumbers[i] = in.readShort();
        }
        return shortNumbers;
      case TYPE_INT_ARRAY:
        length = in.readInt();
        int[] intNumbers = new int[length];
        for (int i = 0; i < length; i++) {
          intNumbers[i] = in.readInt();
        }
        return intNumbers;
      case TYPE_LONG_ARRAY:
        length = in.readInt();
        long[] longNumbers = new long[length];
        for (int i = 0; i < length; i++) {
          longNumbers[i] = in.readLong();
        }
        return longNumbers;
        // #if polish.hasFloatingPoint
      case TYPE_FLOAT_ARRAY:
        length = in.readInt();
        float[] floatNumbers = new float[length];
        for (int i = 0; i < length; i++) {
          floatNumbers[i] = in.readFloat();
        }
        return floatNumbers;
      case TYPE_DOUBLE_ARRAY:
        length = in.readInt();
        double[] doubleNumbers = new double[length];
        for (int i = 0; i < length; i++) {
          doubleNumbers[i] = in.readDouble();
        }
        return doubleNumbers;
        // #endif
      case TYPE_CHAR_ARRAY:
        length = in.readInt();
        char[] characters = new char[length];
        for (int i = 0; i < length; i++) {
          characters[i] = in.readChar();
        }
        return characters;
      case TYPE_BOOLEAN_ARRAY:
        length = in.readInt();
        boolean[] bools = new boolean[length];
        for (int i = 0; i < length; i++) {
          bools[i] = in.readBoolean();
        }
        return bools;
      case TYPE_STRING_ARRAY:
        length = in.readInt();
        String[] strings = new String[length];
        for (int i = 0; i < length; i++) {
          strings[i] = in.readUTF();
        }
        return strings;
      default:
        throw new IOException("Unknown type: " + type);
    }
  }