Hello, AWT(BeanShell) World!

Posted on 12月 7th, 2012 by cx20

AWT(BeanShell)

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

ソースコード

import java.awt.*;
import java.awt.event.*;
 
class Hello extends Frame {
    Hello( String title ) {
        super( title );
        addWindowListener(new HelloWindowAdapter());
        setSize(640, 480);
        setLayout(new FlowLayout(FlowLayout.LEFT));
        label = new Label("Hello, AWT World!");
        add(label);
    }
}
 
class HelloWindowAdapter extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }
}
 
Hello frame = new Hello( "Hello, World" );
frame.setVisible(true);

実行方法

C:¥> SET CLASSPATH=bsh-2.0b4.jar;%CLASSPATH%
C:¥> java bsh.Interpreter hello.bsh

実行結果

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

Tags:

Categories: AWT, BeanShell, Java

コメントを残す

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

WP-SpamFree by Pole Position Marketing