java swing 怎么实现窗口振动效果
玩过qq的人,都知道,可以给对方发一个“窗口抖动”的功能,我现在也想实现窗口抖动,请大家给我一些思路哦?
------解决方案--------------------可能可以通过一个Timer,在Timer执行里改变JFrame的y坐标。
------解决方案--------------------public class shake extends JFrame implements Runnable {
public shake() {
super("shake");
this.setSize(350, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Thread(new shake()).start();
}
@Override
public void run() {
// TODO Auto-generated method stub
for(int i=1; i<=5; i++) {
this.setLocation(0, 10);
try {
Thread.sleep(30);
this.setLocation(20, 20);
Thread.sleep(30);
this.setLocation(0, 0);
Thread.sleep(30);
this.setLocation(20, 0);
Thread.sleep(30);
this.setLocation(0, 20);
Thread.sleep(30);
this.setLocation(0, 0);
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}