2010-12-27 5 views
0

アンドロイドで独自のJavaのRobotクラスを作成してスクリーンキャプチャを行うことにしました。私自身がロボットクラスのソースコードを作成しましたが、問題はここにありますコードの次の行は、コンパイルerror..sayingを投げているアンドロイドで私自身のロボットクラスを作成する際にエラーが発生しました

ピア=((ComponentFactory)ツールキット「型ComponentFactoryで方法createRobot(ロボット、のGraphicsDevice)は引数(ロボット、のGraphicsDevice)のために適用されません」 ).createRobot(これ、スクリーン);

誰もが....解決策になるものを私にお勧めできます

感謝..

+0

それは、「これは」ロボットと画面のインスタンスはGraphicsDeviceでのインスタンスであることを確認して、それが言うことを意味します。 – Nishant

+0

私の完全なコードの私の答えを見てください – manju

答えて

0

ここに私の完全なソースコードは

パッケージcom.example.awtされます。

import java.awt.AWTException; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import java.awt.peer。 ; import java.awt.image。; import java.awt.event。*; import java.lang.reflect.InvocationTargetException;

// import com.sun.media.sound.Toolkit;

import sun.awt.ComponentFactory; //インポートsun.awt.SunToolkit; import sun.security.util.SecurityConstants; import java.awt.Toolkit;

パブリッククラスロボット{

private static final int MAX_DELAY = 60000; 
private RobotPeer peer; 
    private boolean isAutoWaitForIdle = false; 
    private int autoDelay = 0; 
    private static final int LEGAL_BUTTON_MASK = 
         InputEvent.BUTTON1_MASK| 
         InputEvent.BUTTON2_MASK| 
         InputEvent.BUTTON3_MASK; 

    private DirectColorModel screenCapCM = null; 

    public Robot() throws AWTException { 
      if (GraphicsEnvironment.isHeadless()) { 
       throw new AWTException ("headless environment"); 
     } 
     init(GraphicsEnvironment.getLocalGraphicsEnvironment() 
      .getDefaultScreenDevice()); 

     } 
    private void init(GraphicsDevice screen) throws AWTException { 
     checkRobotAllowed(); 
      Toolkit toolkit = Toolkit.getDefaultToolkit(); 
      if (toolkit instanceof ComponentFactory) { 
       peer = ((ComponentFactory)toolkit).createRobot(this, screen); 
      } 
     } 
    public Robot(GraphicsDevice screen) throws AWTException { 
     checkIsScreenDevice(screen); 
      init(screen); 
    } 

    private void checkRobotAllowed() { 
    SecurityManager security = System.getSecurityManager(); 
     if (security != null) { 
      security.checkPermission(SecurityConstants.CREATE_ROBOT_PERMISSION); 
     } 
     } 

    private void checkIsScreenDevice(GraphicsDevice device) { 
      if (device == null || device.getType() != GraphicsDevice.TYPE_RASTER_SCREEN) { 
       throw new IllegalArgumentException ("not a valid screen device"); 
      } 

    } 
    public synchronized BufferedImage createScreenCapture(Rectangle screenRect) { 
     checkScreenCaptureAllowed(); 
     checkValidRect(screenRect); 

     BufferedImage image; 
     DataBufferInt buffer; 
     WritableRaster raster; 

     if (screenCapCM == null) { 
      /* 
    284   * Fix for 4285201 
    285   * Create a DirectColorModel equivalent to the default RGB ColorModel, 
    286   * except with no Alpha component. 
      */ 

      screenCapCM = new DirectColorModel(24, 
          /* red mask */ 0x00FF0000, 
          /* green mask */ 0x0000FF00, 
          /* blue mask */ 0x000000FF); 
     } 

     int pixels[]; 
     int[] bandmasks = new int[3]; 

     pixels = peer.getRGBPixels(screenRect); 
     buffer = new DataBufferInt(pixels, pixels.length); 

     bandmasks[0] = screenCapCM.getRedMask(); 
     bandmasks[1] = screenCapCM.getGreenMask(); 
     bandmasks[2] = screenCapCM.getBlueMask(); 

     raster = Raster.createPackedRaster(buffer, screenRect.width, screenRect.height, screenRect.width, bandmasks, null); 

     image = new BufferedImage(screenCapCM, raster, false, null); 

     return image; 
     } 
    private static void checkValidRect(Rectangle rect) { 
     if (rect.width <= 0 || rect.height <= 0) { 
      throw new IllegalArgumentException ("Rectangle width and height must be > 0"); 
     } 
     } 
    private static void checkScreenCaptureAllowed() { 
     SecurityManager security = System.getSecurityManager(); 
     if (security != null) { 
      security.checkPermission(
      SecurityConstants.READ_DISPLAY_PIXELS_PERMISSION); 
     } 
     } 

}

+0

これは答えではなく、明確化のため、これは元の質問の編集になるはずです。 – smith324

+0

私はあなたが何をしているのか、私のJava内部では古くなっていることを知っているわけではありません。 'this'ポインタをコンストラクタからあなたのファクトリに渡しています。 createRobot()に渡す前に、あなたのロボットクラスが完全に初期化されていますか? – Falmarri

関連する問題