= 概要 =
以下は、GUIのサンプルです。test/junkutil/gui に入っています。
= サンプル =
{{{
package junkutil.gui;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
/**
* GUIをテストする。JUnitが使えないのでmain関数でテストする。
* @author Hiroyuki Shiota
*/
public class GuiTest {
private static LzFrame frame = new LzFrame("テスト", 320, 240);
private static LzDialog dialog = new LzDialog(frame, "ダイアログ", 160, 120, true);
/**
* (publicで、かつ、ActioinEventを引数に取る)コールバック関数
* @param e
*/
public void callback1(ActionEvent e) {
JOptionPane.showMessageDialog(frame, "コールバックされました!");
}
/**
* テストを行う
*/
public void test() {
LzMenu menu = new LzMenu();
menu.addMenu("ファイル/メッセージ,Ctrl+M", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame, "メッセージです!");
}
});
menu.addMenu("ファイル/ダイアログ,Ctrl+D", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(true);
dialog.setEscapeToDispose(true);
}
});
menu.addMenu("ファイル/コールバック,Ctrl+C", new LzCallback(this, "callback1"));
menu.addMenu("ファイル/-"); //区切り線
menu.addMenu("ファイル/終了,Ctrl+Q", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
System.exit(0);
}
});
frame.setJMenuBar(menu.getMenuBar());
frame.setEscapeToDispose(true);
LzLookAndFeel.toSystem();
LzLookAndFeel.update(menu.getMenuBar());
LzLookAndFeel.update(frame);
LzLookAndFeel.update(dialog);
frame.setVisible(true);
}
/**
* メイン関数
* @param args
*/
public static void main(String[] args) {
new GuiTest().test();
}
}
}}}
[[Embed(http://static.sourceforge.jp/thumb/g/2/788/640x640_0.png)]]