Hello, SWT(Rhino) World!

Posted on 12月 21st, 2012 by cx20

SWT(Rhino)

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

ソースコード

importPackage(org.eclipse.swt);
importPackage(org.eclipse.swt.widgets);
importPackage(org.eclipse.swt.layout);
 
var display = new Display();
var shell = new Shell(display);
shell.setText("Hello, World");
 
var layout = new FillLayout(SWT.VERTICAL);
shell.setLayout(layout);
 
var label = new Label(shell,SWT.BORDER);
label.setText("Hello, SWT World!");
 
shell.setSize( 640, 480 );
shell.open();
 
while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
        display.sleep();
    }
}
 
display.dispose();

実行方法

C:¥> jrunscript -cp org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar;. hello.js

実行結果

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

Tags:

Categories: Java, JavaScript, Rhino, SWT

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

WP-SpamFree by Pole Position Marketing