Archive for 1月 2nd, 2013

  1. Hello, SWT(Jasmin) World!

    Posted on 1月 2nd, 2013 by cx20

    SWT(Java)

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

    ソースコード

    ; Produced by NeoJasminVisitor (tinapoc)
    ; http://tinapoc.sourceforge.net
    ; The original JasminVisitor is part of the BCEL
    ; http://jakarta.apache.org/bcel/
    ; Sun Dec 02 01:23:19 JST 2012
     
    .bytecode 50.0
    .source Hello.java
    .class public Hello
    .super java/lang/Object
     
    .method public <init>()V
        .limit stack 1
        .limit locals 1
        .var 0 is this LHello; from Label0 to Label1
     
        Label0:
    .line 5
           0: aload_0
           1: invokespecial java/lang/Object/<init>()V
     
        Label1:
           4: return
     
    .end method
     
    .method public static main([Ljava/lang/String;)V
        .limit stack 4
        .limit locals 5
        .var 0 is arg0 [Ljava/lang/String; from Label3 to Label4
     
        Label3:
    .line 7
           0: new org/eclipse/swt/widgets/Display
           3: dup
           4: invokespecial org/eclipse/swt/widgets/Display/<init>()V
           7: astore_1
     
        .line 8
           8: new org/eclipse/swt/widgets/Shell
          11: dup
          12: aload_1
          13: invokespecial org/eclipse/swt/widgets/Shell/<init>(Lorg/eclipse/swt/widgets/Display;)V
          16: astore_2
     
        .line 9
          17: aload_2
          18: ldc "Hello, World"
          20: invokevirtual org/eclipse/swt/widgets/Shell/setText(Ljava/lang/String;)V
     
        .line 12
          23: new org/eclipse/swt/layout/FillLayout
          26: dup
          27: sipush 512
          30: invokespecial org/eclipse/swt/layout/FillLayout/<init>(I)V
          33: astore_3
     
        .line 13
          34: aload_2
          35: aload_3
          36: invokevirtual org/eclipse/swt/widgets/Shell/setLayout(Lorg/eclipse/swt/widgets/Layout;)V
     
        .line 15
          39: new org/eclipse/swt/widgets/Label
          42: dup
          43: aload_2
          44: sipush 2048
          47: invokespecial org/eclipse/swt/widgets/Label/<init>(Lorg/eclipse/swt/widgets/Composite;I)V
          50: astore 4
     
        .line 16
          52: aload 4
          54: ldc "Hello, SWT World!"
          56: invokevirtual org/eclipse/swt/widgets/Label/setText(Ljava/lang/String;)V
     
        .line 18
          59: aload_2
          60: sipush 640
          63: sipush 480
          66: invokevirtual org/eclipse/swt/widgets/Shell/setSize(II)V
     
        .line 19
          69: aload_2
          70: invokevirtual org/eclipse/swt/widgets/Shell/open()V
     
        Label1:
    .line 21
          73: aload_2
          74: invokevirtual org/eclipse/swt/widgets/Shell/isDisposed()Z
          77: ifne Label0
     
        .line 22
          80: aload_1
          81: invokevirtual org/eclipse/swt/widgets/Display/readAndDispatch()Z
          84: ifne Label1
     
        .line 23
          87: aload_1
          88: invokevirtual org/eclipse/swt/widgets/Display/sleep()Z
          91: pop
          92: goto Label1
     
        Label0:
    .line 27
          95: aload_1
          96: invokevirtual org/eclipse/swt/widgets/Display/dispose()V
     
        Label4:
    .line 28
          99: return
     
    .end method

    コンパイル&実行方法

    C:¥> java -jar jasmin.jar Hello.j
    C:¥> javaw -cp org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar;. Hello

    実行結果

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