我想在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例,上面有这个例子,不过书在家呢。帮顶
[解决办法]