vibrate JFrame - Java Swing

Java examples for Swing:JFrame

Description

vibrate JFrame

Demo Code


//package com.java2s;
import javax.swing.JFrame;

public class Main {
    private final static int VIBRATION_LENGTH = 30;
    private final static int VIBRATION_VELOCITY = 10;

    public static void vibrate(JFrame frame) {
        try {/* w  ww .  j  a va2 s.  c o m*/
            final int originalX = frame.getLocationOnScreen().x;
            final int originalY = frame.getLocationOnScreen().y;
            for (int i = 0; i < VIBRATION_LENGTH; i++) {
                Thread.sleep(10);
                frame.setLocation(originalX, originalY + VIBRATION_VELOCITY);
                Thread.sleep(10);
                frame.setLocation(originalX, originalY - VIBRATION_VELOCITY);
                Thread.sleep(10);
                frame.setLocation(originalX + VIBRATION_VELOCITY, originalY);
                Thread.sleep(10);
                frame.setLocation(originalX, originalY);
            }
        } catch (Exception err) {
            err.printStackTrace();
        }
    }
}

Related Tutorials