Example usage for javax.swing Timer start

List of usage examples for javax.swing Timer start

Introduction

In this page you can find the example usage for javax.swing Timer start.

Prototype

public void start() 

Source Link

Document

Starts the Timer, causing it to start sending action events to its listeners.

Usage

From source file:Main.java

/**
 * Creates an animation to fade the dialog opacity from 0 to 1.
 *//* www .j  a v a 2 s  .c  o  m*/
public static void fadeIn(final JDialog dialog) {
    final Timer timer = new Timer(10, null);
    timer.setRepeats(true);
    timer.addActionListener(new ActionListener() {
        private float opacity = 0;

        @Override
        public void actionPerformed(ActionEvent e) {
            opacity += 0.15f;
            dialog.setOpacity(Math.min(opacity, 1));
            if (opacity >= 1)
                timer.stop();
        }
    });

    dialog.setOpacity(0);
    timer.start();
    dialog.setVisible(true);
}

From source file:Main.java

public static void fadeIn(final Dialog win) {
    if (!win.isUndecorated()) {
        return;// w w  w  . j  av  a  2  s .co  m
    }
    final Timer timer = new Timer(30, null);
    timer.setRepeats(true);
    timer.addActionListener(new ActionListener() {
        private float opacity = 0;

        @Override
        public void actionPerformed(ActionEvent e) {
            opacity += 0.05f;
            win.setOpacity(Math.min(opacity, 1f));
            if (opacity >= 1) {
                timer.stop();
            }
        }
    });
    win.setOpacity(0);
    timer.start();
    win.setVisible(true);
}

From source file:Main.java

/**
 * Creates an animation to fade the dialog opacity from 0 to 1.
 *///from   w  w w . ja v  a2  s. c  o  m
public static void fadeIn(final JDialog dialog) {
    final Timer timer = new Timer(10, null);
    timer.setRepeats(true);
    timer.addActionListener(new ActionListener() {

        private float opacity = 0;

        @Override
        public void actionPerformed(ActionEvent e) {
            opacity += 0.15f;
            dialog.setOpacity(Math.min(opacity, 1));
            if (opacity >= 1) {
                timer.stop();
            }
        }
    });

    dialog.setOpacity(0);
    timer.start();
    dialog.setVisible(true);
}

From source file:Main.java

/**
 * Creates an animation to fade the dialog opacity from 1 to 0.
 *//*from   w w w .  jav a 2  s  . c  om*/
public static void fadeOut(final JDialog dialog) {
    final Timer timer = new Timer(10, null);
    timer.setRepeats(true);
    timer.addActionListener(new ActionListener() {
        private float opacity = 1;

        @Override
        public void actionPerformed(ActionEvent e) {
            opacity -= 0.15f;
            dialog.setOpacity(Math.max(opacity, 0));
            if (opacity <= 0) {
                timer.stop();
                dialog.dispose();
            }
        }
    });

    dialog.setOpacity(1);
    timer.start();
}

From source file:Main.java

/**
 * Creates an animation to fade the dialog opacity from 0 to 1.
 *
 * @param dialog the dialog to fade in/*from w ww  .j av a2s . c om*/
 * @param delay the delay in ms before starting and between each change
 * @param incrementSize the increment size
 */
public static void fadeIn(final JDialog dialog, int delay, final float incrementSize) {
    final Timer timer = new Timer(delay, null);
    timer.setRepeats(true);
    timer.addActionListener(new ActionListener() {
        private float opacity = 0;

        @Override
        public void actionPerformed(ActionEvent e) {
            opacity += incrementSize;
            dialog.setOpacity(Math.min(opacity, 1)); // requires java 1.7
            if (opacity >= 1) {
                timer.stop();
            }
        }
    });

    dialog.setOpacity(0); // requires java 1.7
    timer.start();
    dialog.setVisible(true);
}

From source file:Main.java

/**
 * Creates an animation to fade the dialog opacity from 1 to 0.
 *//*w ww .  java 2s. com*/
public static void fadeOut(final JDialog dialog) {
    final Timer timer = new Timer(10, null);
    timer.setRepeats(true);
    timer.addActionListener(new ActionListener() {

        private float opacity = 1;

        @Override
        public void actionPerformed(ActionEvent e) {
            opacity -= 0.15f;
            dialog.setOpacity(Math.max(opacity, 0));
            if (opacity <= 0) {
                timer.stop();
                dialog.dispose();
            }
        }
    });

    dialog.setOpacity(1);
    timer.start();
}

From source file:Main.java

/**
 * Creates an animation to fade the dialog opacity from 1 to 0, and then
 * dispose.//w ww . j ava 2  s .co  m
 *
 * @param dialog the dialog to fade out
 * @param delay the delay in ms before starting and between each change
 * @param incrementSize the increment size
 */
public static void fadeOut(final JDialog dialog, int delay, final float incrementSize) {
    final Timer timer = new Timer(delay, null);
    timer.setRepeats(true);
    timer.addActionListener(new ActionListener() {
        private float opacity = 1;

        @Override
        public void actionPerformed(ActionEvent e) {
            opacity -= incrementSize;
            dialog.setOpacity(Math.max(opacity, 0)); // requires java 1.7
            if (opacity < 0) {
                timer.stop();
                dialog.dispose();
            }
        }
    });

    dialog.setOpacity(1); // requires java 1.7
    timer.start();
}

From source file:Main.java

private static void triggerBringToFront(final JFrame f, final int delayMS) {
    Timer timer = new Timer(delayMS, new ActionListener() {
        @Override/*  w  w  w.j a  va 2  s.  c  om*/
        public void actionPerformed(ActionEvent e) {
            // This will only cause the task bar entry
            // for this frame to blink
            // f.toFront();

            // This will bring the window to the front,
            // but not make it the "active" one
            // f.setAlwaysOnTop(true);
            // f.setAlwaysOnTop(false);

            if (!f.isActive()) {
                f.setState(JFrame.ICONIFIED);
                f.setState(JFrame.NORMAL);
            }
        }
    });
    timer.setRepeats(false);
    timer.start();
}

From source file:TickTockInner.java

private void go() {
    Timer t = new Timer(1000, new Ticker());
    t.start();
    JOptionPane.showMessageDialog(null, "Click OK to exit program");
    System.exit(0);/*  w  w  w  .ja v a 2 s. co m*/
}

From source file:Main.java

public Main() {
    setSize(250, 100);//from ww w .j  a v  a 2s .c o  m
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Timer timer = new Timer(500, this);
    timer.start();
    setVisible(true);
}