Archive for 12月 25th, 2012

  1. Hello, AWT(Fantom) World!

    Posted on 12月 25th, 2012 by cx20

    AWT(Fantom)

    AWT(Abstract Window Toolkit) は Java で GUI を扱うためのライブラリである。
    J2SE 1.2 以降は AWT を拡張した Swing が使われることが多くなっている。
    以下は Fantom による AWT の使用例となっている。

    ソースコード

    using [java] java.lang
    using [java] java.awt
    using [java] java.awt.event
    using concurrent
     
    class Hello
    {
        Void main()
        {
            label := Label("Hello, AWT World!")
            frame := Frame("Hello, World")
            {
                addWindowListener( HelloWindowAdapter.make|WindowEvent e| {})
                add(label)
                setSize(640, 480)
                setLayout(FlowLayout(FlowLayout.LEFT))
                setVisible(true)
            }
     
            Actor.sleep(Duration.maxVal)
        }
    }
     
    class HelloWindowAdapter : WindowAdapter
    {
        new make(|WindowEvent| cb) { this.cb = cb }
        override Void windowClosing(WindowEvent? e) { System.exit(0) }
        |WindowEvent| cb
    }

    実行方法

    C:¥> fan hello.fan

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, AWT World!                         |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+