Archive for 12月 29th, 2012

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

    Posted on 12月 29th, 2012 by cx20

    Java 2D

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

    ソースコード

    using [java] java.awt
    using [java] javax.swing
    using concurrent
     
    class Hello
    {
        Void main()
        {
            canvas := Canvas()
            frame := JFrame("Hello, World")
            {
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
                add(canvas)
                setSize(640, 480)
                setVisible(true)
                canvas.createBufferStrategy(2)
                strategy := canvas.getBufferStrategy
                g2 := (Graphics2D)strategy.getDrawGraphics
                while(true)
                {
                    g2.drawString("Hello, Java 2D World!", 0, 16 )
                    strategy.show
                    Actor.sleep(200ms)
                }
            }
            Actor.sleep(Duration.maxVal)
        }
    }

    実行方法

    C:¥> fan hello.fan

    実行結果

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