[java]JFrameにむだに動きをつけてみる - timingframeworkで。 2008/12/22

Javaです。timingframeworkです。
JFrameに無駄な動きをつけてみます。

timingframework: Timing is Everything

PropertySetterを使ってsize,locationを利用して簡単動きをつけてみます。
timingframeworkを使うとアニメーションをつけるのが簡単になりますね。
swingのイベントの仕組みにのっかてる感じがして副作用がでなさそうです。

以下コード

package tf;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.jdesktop.animation.timing.Animator;
import org.jdesktop.animation.timing.interpolation.PropertySetter;
import org.jdesktop.animation.timing.triggers.ActionTrigger;

public class TestFrameMain {

public static void main(String[] args) {

final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setVisible(true);

JFrame frame2 = new JFrame();
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.setSize(300, 300);

frame2.getContentPane().add(new JPanel() {
{
add(new JButton("GO") {

{
final Animator animator = PropertySetter
.createAnimator(600, frame, "size",
new Dimension(10, 10), new Dimension(
500, 300), new Dimension(600,
400), new Dimension(500, 300));

ActionTrigger.addTrigger(this, animator);

addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {

// Point now_p = frame.getLocation();
Point now_p = new Point(300, 500);
PropertySetter
.createAnimator(
600,
frame,
"location",
new Point(now_p.x + 250,
now_p.y + 150),
now_p,
new Point(now_p.x - 50,
now_p.y - 50), now_p)
.start();

}
});
}
});
}

});
frame2.setVisible(true);
}
}

: