Hello, SWT(BeanShell) World!

Posted on 12月 9th, 2012 by cx20

SWT(BeanShell)

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

ソースコード

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
 
display = new Display();
shell = new Shell(display);
shell.setText("Hello, World");
 
layout = new FillLayout(SWT.VERTICAL);
shell.setLayout(layout);
 
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:¥> SET CLASSPATH=bsh-2.0b4.jar;org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar;%CLASSPATH%
C:¥> java bsh.Interpreter hello.bsh

実行結果

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

Tags:

Categories: BeanShell, Java, SWT

コメントを残す

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

WP-SpamFree by Pole Position Marketing