Archive for 11月 27th, 2012

  1. Hello, SWT(Jython) World!

    Posted on 11月 27th, 2012 by cx20

    SWT(Jython)

    SWT(Standard Widget Toolkit) は Java で GUI を扱うためのライブラリである。
    IBM により AWT や Swing を置き換える目的で作成された。
    以下は Jython による SWT の使用例となっている。

    ソースコード

    from java.lang import System
    from org.eclipse.swt import SWT
    from org.eclipse.swt.widgets import Display
    from org.eclipse.swt.widgets import Shell
    from org.eclipse.swt.widgets import Label
    from org.eclipse.swt.layout import FillLayout
     
    display = Display()
    shell = Shell(display)
    shell.setText("Hello, World")
     
    layout = FillLayout(SWT.VERTICAL)
    shell.setLayout(layout)
     
    label = Label(shell,SWT.BORDER)
    label.setText("Hello, SWT World!")
     
    shell.setSize( 640, 480 )
    shell.open()
     
    while not shell.isDisposed():
        if not display.readAndDispatch():
            display.sleep()
     
    display.dispose()

    実行方法

    C:¥> SET CLASSPATH=org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar;%CLASSPATH%
    C:¥> jython Hello.py

    実行結果

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