RobotBaram.net
  Home
  About Me
  Life is...
  Gallery
  Project
  Program
  Guest Book  
Login
Life is
 
   ScrollableImageField.java (11.7K) [0] DATE : 2009-11-10 02:20:14



import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;

class ScrollingImageRecipe extends UiApplication {

 private class ScrollingImageScreen extends MainScreen {
  private static final int HORZ_SCROLL_FACTOR = 10;
  private static final int VERT_SCROLL_FACTOR = 10;

  Bitmap bitmap;
  int left = 0;
  int top = 0;
  int maxLeft = 0;
  int maxTop = 0;
  
  public ScrollingImageScreen() {
   bitmap = Bitmap.getBitmapResource("test.png");
   
   if (bitmap == null) {
    UiApplication.getUiApplication().invokeLater(new Runnable() {
     public void run() {
      Dialog.alert("Failed to load image");
      System.exit(0);
     }
    });
    return;
   }
   
   if (bitmap.getWidth() > Graphics.getScreenWidth()) {
    maxLeft = bitmap.getWidth() - Graphics.getScreenWidth();
   }
   
   if (bitmap.getHeight() > Graphics.getScreenHeight()) {
    maxTop = bitmap.getHeight() - Graphics.getScreenHeight();
   }
  }
  
  protected void paint(Graphics graphics) {
   if (bitmap != null) {
    graphics.drawBitmap(0, 0, Graphics.getScreenWidth(), Graphics.getScreenHeight(),
      bitmap, left, top);
   }
  }
  
  protected boolean navigationMovement(int dx, int dy, int status, int time) {
   left += (dx * HORZ_SCROLL_FACTOR);
   top += (dy * VERT_SCROLL_FACTOR);

   if (left < 0) left = 0;
   if (top < 0) top = 0;
   if (left > maxLeft) left = maxLeft;
   if (top > maxTop) top = maxTop;

   invalidate();

   return true;
  }
 }

    public static void main(String[] args){
     ScrollingImageRecipe app = new ScrollingImageRecipe();
        app.enterEventDispatcher();
    }
   
    ScrollingImageRecipe() {
     pushScreen(new ScrollingImageScreen());
    }

}


 
   
작성일 : 09-11-10 02:14