Ejemplo n.º 1
0
  protected void startApp() throws MIDletStateChangeException {
    final Display display = Display.getDisplay(this);

    final MyCanvas myCanvas = new MyCanvas();
    myCanvas.setCommandListener(this);

    cmd_exit = new Command("Exit", Command.EXIT, 0);
    myCanvas.addCommand(cmd_exit);

    display.setCurrent(myCanvas);

    Thread thread =
        new Thread() {
          public void run() {
            super.run();

            InputStream inputStream = null;

            try {
              // inputStream = getClass().getResourceAsStream( "Pothana.ttf" );
              inputStream = getClass().getResourceAsStream("SCRIPTIN.ttf");

              TrueTypeRegistry.instance.registerTrueType("FONT1", inputStream);

              // inputStream = getClass().getResourceAsStream( "Tikkana.ttf" );
              inputStream = getClass().getResourceAsStream("UNCLEBOBMF.ttf");

              TrueTypeRegistry.instance.registerTrueType("FONT2", inputStream);

              text1 =
                  new TrueTypeText(
                      "FONT1",
                      -0.3,
                      0,
                      // getUTF16FileData( "telugu1.txt" ),
                      "True",
                      24,
                      COLOR_BLUE,
                      (useFilling ? COLOR_YELLOW : null));
              // text1.translate( 0.07d, 0 );
              // text1.rotate(-7d*Math.PI/30d, 0, 0 );

              text2 =
                  new TrueTypeText(
                      "FONT2",
                      0.4,
                      0,
                      // getTeluguUTF16FileDataAndTransposeForTikkanaFont( "telugu1.txt" ),
                      "TYPE",
                      24,
                      COLOR_RED,
                      (useFilling ? COLOR_GRAY : null));
              // text2.translate( 0.07d, 0 );
            } catch (TrueTypeException e) {
              System.out.println("Unable to load font!");
              e.printStackTrace();
            } catch (Throwable t) {
              System.out.println("Error!");
              t.printStackTrace();
            } finally {
              try {
                if (inputStream != null) {
                  inputStream.close();
                }
              } catch (Throwable ignore) {
              }
            }

            // initialize graphics
            int attemptsLeft = 10;
            Displayable displayCurrent = null;
            while ((attemptsLeft-- > 0) && (displayCurrent = display.getCurrent()) == null) {
              try {
                Thread.sleep(1000);
              } catch (InterruptedException ignore) {
              }
            }
            if (displayCurrent == null) {
              throw new RuntimeException("Display.getCurrent() returns null!");
            }
            WIDTH = displayCurrent.getWidth();
            HEIGHT = displayCurrent.getHeight();

            view = new View(WIDTH, HEIGHT);

            timer = new TimerThread(ANIMATION_DELAY, myCanvas);
            timer.start();
          }
        };

    thread.start();
  }