haXe(v2.04)でaswing(1_5というパック?)を使う例。
/**
* Sample002.as
* Thanks!! -> http://www.matzmtok.com/blog/?p=18
*/
import org.aswing.event.InteractiveEvent ;
import org.aswing.ASColor;
import org.aswing.Container;
import org.aswing.EmptyLayout;
import org.aswing.JSlider;
import org.aswing.JWindow;
import org.aswing.SoftBoxLayout;
import org.aswing.ButtonGroup;
import org.aswing.BoxLayout;
import org.aswing.BorderLayout;
import org.aswing.JLabel;
import org.aswing.JFrame;
import org.aswing.JPanel;
import org.aswing.JButton;
import org.aswing.JRadioButton;
import org.aswing.geom.IntPoint;
import org.aswing.geom.IntDimension;
class Sample002 extends JWindow{
private var rbX:JRadioButton;
private var rbY:JRadioButton;
private var group:ButtonGroup;
private var zzlayout:BoxLayout;
private var frame:JFrame;
public var bg:ButtonGroup;
public var title:String;
public function new() {
super(flash.Lib.current, true);
title = 'Example of BoxLayout';
initUI();
}
private function initUI():Void {
setBackground(new ASColor(0xffffff));
var rbPanel:JPanel = new JPanel();
rbX = new JRadioButton('BoxLayout.X_AXIS');
rbY = new JRadioButton('BoxLayout.Y_AXIS');
zzlayout = new BoxLayout();
rbX.addSelectionListener(onRadioChanged);
rbY.addSelectionListener(onRadioChanged);
rbX.setSelected(true);
group = new ButtonGroup();
group.append(rbX);
group.append(rbY);
rbPanel.append(new JLabel('方向'));
rbPanel.append(rbX);
rbPanel.append(rbY);
rbPanel.setLocation(new IntPoint(0, 0));
rbPanel.setSize(new IntDimension(400, 30));
getContentPane().append(rbPanel);
var gapPanel:JPanel = new JPanel();
gapPanel.append(new JLabel('間隔'));
var slider:JSlider = new JSlider(JSlider.HORIZONTAL, 0, 30, 0);
slider.addStateListener(onSliderChange);
gapPanel.append(slider);
gapPanel.setLocation(new IntPoint(0, 20));
gapPanel.setSize(new IntDimension(400, 30));
gapPanel.setBackground(new org.aswing.ASColor(0xFF00FF)); // 効かない?
gapPanel.setToolTipText("xxxTIPxxx");
getContentPane().append(gapPanel);
frame = new JFrame(this, title);
getContentPane().append(frame);
frame.getContentPane().setLayout(zzlayout);
frame.setLocation(new IntPoint(30, 50));
frame.setSize(new IntDimension(250, 150));
// たくさん並べるとよしなに幅や高さを等分してくれる
frame.getContentPane().append(new JButton('Button 1'));
frame.getContentPane().append(new JButton('Button 2'));
frame.getContentPane().append(new JButton('Button 3'));
frame.getContentPane().append(new JButton('Button 4'));
frame.show();
}
public function onRadioChanged(e:InteractiveEvent):Void {
var rb:JRadioButton = cast(e.target,JRadioButton);
switch(rb){
case rbX:
zzlayout.setAxis(BoxLayout.X_AXIS);
case rbY:
zzlayout.setAxis(BoxLayout.Y_AXIS);
default:
trace("cannot change layout!");
}
updateLayout();
}
public function onSliderChange(e:InteractiveEvent):Void {
var s:JSlider = cast(e.target,JSlider);
zzlayout.setGap(s.getValue());
updateLayout();
}
private function updateLayout():Void {
frame.getContentPane().setLayout(zzlayout);
}
}
これを、以下のように呼び出す。
import org.aswing.geom.IntPoint;
import org.aswing.geom.IntDimension;
class Main
{
static function main()
{
var app:Sample002 = new Sample002();
app.setLocation(new IntPoint(0, 0));
app.setSize(new IntDimension(500, 500));
app.show();
// flash.Lib.current.addChild(new Sample002());
}
}
ちなみに、haxeコマンドに与えるcompile.hxmlはこんな感じ。
-swf-header 500:500:20:FFFFFF
-swf Main.swf
-cp hxclasses
-swf-lib concat.swf
-swf-version 9
-main Main