3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Processingで使用しているJFrameインスタンスにアクセス

Last updated at Posted at 2015-06-07

ウィンドウの初期位置設定とウィンドウの位置取得の際に必要になったためメモ


**補足** この記事ではProcessing2を扱っている Processing3では仕様が変わっている為, ウィンドウの位置を変更する手順が異なる

Processingで扱っているJFrameの変数名は frame なので
そこにアクセスしたらできた
ただしsetup()内でウィンドウ初期位置設定はできない(と思う)ので
サンプルコードのようにフラグを用意してあげる

FrameTest.pde
//初期位置設定用フラグを宣言
boolean flag;

void setup(){
    //frameはJFrameか確認
    println(frame.getClass().getName());
    //フラグの初期値設定
    flag = false;
}
void draw(){
    //drawの最初だけ呼び出し
    if (!flag) {
        frame.setLocation(200, 200);
        flag = true;
    }

    //ウィンドウの位置を取得
    println("x location : " + frame.getLocation().x);
    println("y location : " + frame.getLocation().y);
}

参考URL
http://forum.processing.org/one/topic/how-to-set-the-initial-position-of-the-sketch-window.html

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?