当前位置: 代码迷 >> Eclipse >> 小弟我想在java中实现振动效果,但出了有关问题
  详细解决方案

小弟我想在java中实现振动效果,但出了有关问题

热度:38   发布时间:2016-04-23 14:12:22.0
我想在java中实现振动效果,但出了问题
能帮我看看代码吗?
package Moving;

import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.event.*;
import java.math.*;
import java.util.*;
import java.lang.*;

public class Moving extends JFrame implements ActionListener
{
 static Moving frm =new Moving();
 static JButton btn;
 public static void main(String args[])
 {
frm.setTitle("振动效果");
frm.setSize(240,160);
frm.setLayout(null);
btn=new JButton("振动");
btn.setBounds(120,80,60,30);
btn.addActionListener(frm);
frm.add(btn);
frm.setVisible(true);
 }
 public void actionPerformed(ActionEvent e)
 {

int rand=5;
  int recordx ;
  int recordy ;
  Random random = new Random();
  for (int i = 0; i < 50; i++)
  {
  int x = random.nextInt(rand);
  int y = random.nextInt(rand);
  if (x % 2 == 0)
  {
  frm.LEFT_ALIGNMENT = frm.LEFT_ALIGNMENT + x;
  }
  else
  {
  frm.LEFT_ALIGNMENT = frm.LEFT_ALIGNMENT - x;
  }
  if (y % 2 == 0)
  {
  frm.TOP_ALIGNMENT = frm.TOP_ALIGNMENT + y;
  }
  else
  {
  frm.TOP_ALIGNMENT = frm.TOP_ALIGNMENT - y;
  }
  //System.Threading.Thread.Sleep(1);
  }
  frm.LEFT_ALIGNMENT = recordx;
  frm.TOP_ALIGNMENT = recordy;
 
 }
}


------解决方案--------------------
<Swing Hacks> Hack 38. Earthquake Dialog
------解决方案--------------------
不太会,我有一本参考书Java开发1200例,上面有这个例子,不过书在家呢。帮顶
------解决方案--------------------
探讨

引用:
<Swing Hacks> Hack 38. Earthquake Dialog

什么意思?能详细点吗?

------解决方案--------------------
frm.LEFT_ALIGNMENT 值 不可以修改 .
------解决方案--------------------
学习了
------解决方案--------------------
呵呵,c#我会,java到时没弄过

帮顶了啊,祝你好运
  相关解决方案