Beispiel #1
0
 /*--------------------------------------------------
  * Key code event handling
  *-------------------------------------------------*/
 protected void keyPressed(int keyCode) {
   int h = image.getHeight() / 2;
   int w = image.getWidth() / 2;
   if (keyCode == -1) {
     if (this.mY > h) this.mY = this.mY - 5;
   } else if (keyCode == -2) {
     if (this.mY < getHeight() - h) this.mY = this.mY + 5;
   } else if (keyCode == -3) {
     if (this.mX > w) this.mX = this.mX - 5;
   } else if (keyCode == -4) {
     if (this.mX < getWidth() - w) this.mX = this.mX + 5;
   }
   repaint();
 }
  public Form getSupportMe() {
    if (frmSupportMe == null) {
      // ---------------------------------------------
      // Form f = ...
      frmSupportMe = new Form("Support Me");
      frmSupportMe.setLayout(new BorderLayout());

      Image bimage = null;
      try {
        bimage = Image.createImage("/images/metaLabSmall.png");
      } catch (IOException ex) {
        ex.printStackTrace();
      }

      Label bottomText = new Label(bimage);
      bottomText.setAlignment(Component.CENTER);
      bottomText.setText("Our Logo");
      bottomText.setTextPosition(Component.BOTTOM);

      Container buttonBar = new Container(new BoxLayout(BoxLayout.X_AXIS));
      buttonBar.addComponent(new Button("Add"));
      buttonBar.addComponent(new Button("Remove"));
      buttonBar.addComponent(new Button("Edit"));
      buttonBar.addComponent(new Button("Send"));
      buttonBar.addComponent(new Button("Exit"));

      frmSupportMe.addComponent(BorderLayout.CENTER, bottomText);
      frmSupportMe.addComponent(BorderLayout.SOUTH, buttonBar);
      frmSupportMe.addCommand(mBackCommand);
      frmSupportMe.addCommandListener(this); // Use setCommandListener() with LWUIT 1.3 or earlier.
    }
    return frmSupportMe;
  }
Beispiel #3
0
  public Image getImage2() {
    if (image2 == null) {

      try {
        image2 = Image.createImage("/com/grevzin/pct/logo-sp.png");
      } catch (java.io.IOException e) {
        e.printStackTrace();
      }
    }
    return image2;
  }
Beispiel #4
0
  /*--------------------------------------------------
   * Constructor
   *-------------------------------------------------*/
  public KeyCodeCanvas(KeyCodes midlet) {
    this.midlet = midlet;

    // Create exit command & listen for events
    cmExit = new Command("Exit", Command.EXIT, 1);
    addCommand(cmExit);
    try {
      image = Image.createImage("/nosebleed.png");
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    setCommandListener(this);
  }
  public void startApp() {
    if (svgCanvas == null) {
      // If there is a splash screen defined, show it immediately.
      boolean hasSplash = ((splashImageName != null) && !"".equals(splashImageName));

      if (hasSplash) {
        InputStream splashStream = getClass().getResourceAsStream(splashImageName);

        try {
          Image splashImage = Image.createImage(splashStream);
          splashCanvas = new SplashCanvas(splashImage);
        } catch (IOException ioe) {
          ioe.printStackTrace();
          hasSplash = false;
        }

        if (splashCanvas != null) {
          Display.getDisplay(this).setCurrent(splashCanvas);
        }
      }

      long start = System.currentTimeMillis();

      // Get input stream to the SVG image stored in the MIDlet's jar.
      InputStream svgDemoStream = getClass().getResourceAsStream(svgImageName);

      // Build an SVGImage instance from the stream
      svgImage = null;

      if (svgDemoStream != null) {
        try {
          svgImage = (SVGImage) SVGImage.createImage(svgDemoStream, null);
        } catch (IOException io) {
          io.printStackTrace();
        }
      }

      if (svgImage == null) {
        throw new Error(ERROR_COULD_NOT_LOAD_SVG + svgImageName);
      }

      // Build an SVGAnimator from the SVGImage. The SVGAnimator will handle
      // all the animation details and run the SVG animation in a
      // Canvas instance.
      svgAnimator = SVGAnimator.createAnimator(svgImage);

      // Set to 10 fps (frames per second)
      svgAnimator.setTimeIncrement(0.01f);

      // Get the Canvas managed by the SVGAnimator and set the
      // svgImage's size to the canvas display area.
      svgCanvas = (Canvas) svgAnimator.getTargetComponent();
      svgImage.setViewportWidth(svgCanvas.getWidth());
      svgImage.setViewportHeight(svgCanvas.getHeight());

      // Hook the exit command so that we can exit the animation demo.
      svgCanvas.addCommand(exitCommand);
      svgCanvas.setCommandListener(this);

      // The SVG root element is used to reset the time on a stop operation.
      doc = svgImage.getDocument();
      svg = (SVGSVGElement) doc.getDocumentElement();

      // Hook-in key listeners to play, pause and stop the animation.
      svgAnimator.setSVGEventListener(this);

      long end = System.currentTimeMillis();

      if (hasSplash) {
        long waitMore = SPLASH_MIN_LENGTH - (end - start);

        if (waitMore > 0) {
          try {
            Thread.currentThread().sleep(waitMore);
          } catch (InterruptedException ie) {
            // Do nothing.
          }
        }
      }

      if (autoStart) {
        svgAnimator.play();
        state = STATE_PLAYING;
        System.err.println("PLAYING...");
      }
    }

    Display.getDisplay(this).setCurrent(svgCanvas);
    resumeAnimation();
  }
Beispiel #6
0
  // for initilization purpose and call in the Game() constructor
  public void init() {
    try {
      this.userWins = 0;
      this.compWins = 0;

      this.colSelected = 0;
      this.rowSelected = 0;
      // repaint() ;

      // Getting the maximum width and height of the Canvas
      this.maxX = this.getWidth();
      this.maxY = this.getHeight();

      this.alert =
          new Alert(
              "Score",
              "User  "
                  + String.valueOf(this.userWins)
                  + "\nDevice  "
                  + String.valueOf(this.compWins),
              null,
              AlertType.INFO);

      this.animated = this.parent.getAnimate();

      // Initilizing the Command
      this.score = new Command("Score", Command.ITEM, 2);
      this.addCommand(this.score);
      // this.setCommandListener( this ) ;

      this.newG = new Command("New", Command.ITEM, 1);
      this.addCommand(this.newG);

      this.addCommand(this.back);

      this.setCommandListener(this);

      this.random = new Random();

      // Settings the framem variable
      this.frame = 0;

      this.sq = new int[3][4];

      // Initializing the sq[][] array to -1
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          this.sq[i][j] = -1;
        }
      }

      // Setting the userSymbol
      if (this.userSymbol == -1) {
        this.userSymbol = 0;
      } else if (this.userSymbol == 0) {
        this.userSymbol = 1;
      } else if (this.userSymbol == 1) {
        this.userSymbol = 0;
      }

      // Setting the compSymbol
      if (this.compSymbol == -1) {
        this.compSymbol = 1;
      } else if (this.compSymbol == 0) {
        this.compSymbol = 1;
      } else if (this.compSymbol == 1) {
        this.compSymbol = 0;
      }

      // Declaring timer and timertask
      TimerTask task =
          new TimerTask() {
            public void run() {
              if (frame == 0) {
                if (animated == true) {
                  frame = 1;
                }
              } else if (frame == 1) {
                if (animated == true) {
                  frame = 0;
                }
              }

              // Checking whether all chances are finished
              int c = 0;
              for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                  if (sq[i][j] == -1) {
                    c++;
                  }
                }
              }

              if (c == 0) {
                alert =
                    new Alert(
                        "Draw !",
                        "User  "
                            + String.valueOf(userWins)
                            + "\nDevice  "
                            + String.valueOf(compWins),
                        null,
                        AlertType.INFO);
                parent.setDisplayable(alert);
                newGame();
              }

              repaint();
            }
          };

      timer = new Timer();
      timer.scheduleAtFixedRate(task, 400, 400);

      // Initialising images

      if (this.maxX < 150 && this.maxY < 150) {
        this.imgWidth = 16;
        this.imgHeight = 16;
        this.crossImage = Image.createImage("/cross16.png");
        this.zeroImage = Image.createImage("/naught16.png");
      } else {
        this.imgWidth = 32;
        this.imgHeight = 32;
        this.crossImage = Image.createImage("/cross32.png");
        this.zeroImage = Image.createImage("/naught32.png");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }