void () { myNaturalLocation = myWindow.getLocation(); myStartTime = System.currentTimeMillis(); new Animator("EarthQuake", 10, 70, true) { @Override public void paintNow(int frame, int totalFrames, int cycle) { final long elapsed = System.currentTimeMillis() - myStartTime; final double waveOffset = (elapsed % 70) / 70d; final double angle = waveOffset * 2d * Math.PI; final int shakenX = (int)((Math.sin(angle) * 10) + myNaturalLocation.x); myWindow.setLocation(shakenX, myNaturalLocation.y); myWindow.repaint(); if (elapsed > 150) { suspend(); myWindow.setLocation(myNaturalLocation); myWindow.repaint(); Disposer.dispose(this); } } }.resume(); }