Archive for 12月 23rd, 2012

  1. Hello, Java 2D(Rhino) World!

    Posted on 12月 23rd, 2012 by cx20

    Java 2D(Rhino)

    Java 2D は Java による 2D グラフィックライブラリである。
    以下は Rhino による Java 2D の使用例となっている。

    ソースコード

    importPackage(java.awt);
    importPackage(javax.swing);
     
    var frame = new JFrame();
    frame.setTitle("Hello, World");
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    frame.setSize(640,480);
     
    canvas = new Canvas();
     
    frame.add(canvas);
    frame.setVisible(true);
     
    canvas.createBufferStrategy(2);
    strategy = canvas.getBufferStrategy();
    g2 = strategy.getDrawGraphics();
    while(true)
    {
        g2.drawString("Hello, Java 2D World!", 0, 16 );
        strategy.show();
        java.lang.Thread.sleep(200);
    }
     
    while(1) {java.lang.Thread.sleep(1000);}

    コンパイル&実行方法

    C:¥> jrunscript hello.js

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Java 2D World!                     |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+