无意中发现的好玩代码:摇动的Java对话框
百度广告
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.Timer;
public class Main {
JDialog dialog;
Point naturalLocation;
Timer shakeTimer;
public Main(JDialog d) {
dialog = d;
}
public void startShake() {
final long startTime;
naturalLocation = dialog.getLocation();
startTime = System.currentTimeMillis();
shakeTimer = new Timer(5, new ActionListener() {
public void actionPerformed(ActionEvent e) {
double TWO_PI = Math.PI * 2.0;
double SHAKE_CYCLE = 50;
long elapsed = System.currentTimeMillis() - startTime;
double waveOffset = (elapsed % SHAKE_CYCLE) / SHAKE_CYCLE;
double angle = waveOffset * TWO_PI;
编辑推荐:
温馨提示:因考试政策、内容不断变化与调整,长理培训网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准! (责任编辑:长理培训)
点击加载更多评论>>