0

I'm writing a sketch in Processing and I'm curious how I can get the position of the OS's window that the sketch lives in. If I use getPosition() (part of java.awt) I only get the position of the viewport within the window.

4

1 に答える 1

2

getLocationOnScreen()から継承したものを使用できますが、最初java.awt.Componentにアプレットを確認する必要があります。isShowing()

void draw(){
  if(frame.isShowing()) println(frame.getLocationOnScreen());
}

またはもう少しグラフィカル:

void draw(){
  if(frame.isShowing()) {
    java.awt.Point pt = frame.getLocationOnScreen();
    background(255);
    rectMode(CENTER);
    rect(map(pt.x,0,displayWidth,0,width),//use screenWidth instead of displayWidth in Processing 1.5.1 or older
         map(pt.y,0,displayHeight,0,height),//use screenHeight instead of displayHeight in Processing 1.5.1 or older
         10,10);
  }
}

どこ

Frame frame = ( (PSurfaceAWT.SmoothCanvas) ((PSurfaceAWT)surface).getNative()).getFrame();

P2D(またはこの回答FX2Dをチェックするなどの他のレンダラーについて)

于 2012-12-16T12:25:48.177 に答える