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:MainClass.java

public static void main(String args[]) {
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Hello World Timer");
        }//from   www . j a  v  a  2  s  .  c  om
    };
    Timer timer = new Timer(500, actionListener);
    timer.start();
}

From source file:MainClass.java

public static void main(String[] args) {
    Timer t = new Timer(1000, new Ticker());
    t.start();
    JOptionPane.showMessageDialog(null, "Click OK to exit program");
    System.exit(0);/*from w ww .  j  a v  a 2 s .c  o m*/
}

From source file:TimerSample.java

public static void main(String args[]) {
    new JFrame().setVisible(true);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Hello World Timer");
        }//from   www  . j  a v a2  s.c om
    };
    Timer timer = new Timer(500, actionListener);
    timer.start();
}

From source file:TimerSample.java

public static void main(String args[]) {
    Runnable runner = new Runnable() {
        public void run() {
            ActionListener actionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    System.out.println("Hello World Timer");
                }//  ww  w  .  j  a v  a2s .c o  m
            };
            Timer timer = new Timer(500, actionListener);
            timer.start();
        }
    };
    EventQueue.invokeLater(runner);
}

From source file:TimerSample.java

public static void main(String args[]) {
    Runnable runner = new Runnable() {
        public void run() {
            Timer.setLogTimers(true);
            ActionListener actionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    System.out.println("Hello World Timer");
                }//ww w. ja  va 2 s .  c  om
            };
            Timer timer = new Timer(500, actionListener);
            timer.start();
        }
    };
    EventQueue.invokeLater(runner);
}

From source file:MainClass.java

License:asdf

public static void main(String[] args) {
    Timer timer = new Timer(1000, new MyTimerActionListener());

    timer.start();
    try {/*w w  w.j a  v  a 2s. c  om*/
        Thread.sleep(10000);
    } catch (InterruptedException e) {
    }
    timer.stop();
}

From source file:TimerTest.java

public static void main(String[] args) {
    ActionListener listener = new TimePrinter();

    // construct a timer that calls the listener
    // once every 10 seconds
    Timer t = new Timer(10000, listener);
    t.start();

    JOptionPane.showMessageDialog(null, "Quit program?");
    System.exit(0);/*from   w  w w . j  av  a  2 s. co m*/
}

From source file:Main.java

public static void main(String[] args) {
    Runnable r = new Runnable() {
        @Override//from   www.  j  av  a2 s .  c o  m
        public void run() {
            JPanel gui = new JPanel();

            final AnimatedImage[] tiles = new AnimatedImage[2];
            for (int ii = 0; ii < tiles.length; ii++) {
                tiles[ii] = new AnimatedImage();
                gui.add(new JLabel(new ImageIcon(tiles[ii])));
            }
            ActionListener listener = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    for (int i = 0; i < tiles.length; i++) {
                        tiles[i].paintImage();
                        gui.repaint();
                    }
                }
            };
            Timer timer = new Timer(50, listener);
            timer.start();

            JOptionPane.showMessageDialog(null, gui);
            timer.stop();
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();

    JTextArea textArea = new JTextArea();
    f.add(new JScrollPane(textArea), BorderLayout.CENTER);

    Timer timer = new Timer(1000, new ActionListener() {
        @Override/*from  w ww  .j  a  va  2 s.c o  m*/
        public void actionPerformed(ActionEvent e) {
            textArea.append("bla");
        }
    });
    timer.setRepeats(true);
    timer.start();
    JButton button = new JButton("Click me");
    button.addActionListener(e -> {
        System.out.println("Before option pane");
        JOptionPane.showMessageDialog(f, "A message dialog");
        System.out.println("After option pane");
    });
    f.add(button, BorderLayout.SOUTH);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            final Date date = new Date();
            final JLabel timeLabel = new JLabel(date.toString());
            Timer timer = new Timer(1000, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    date.setTime(System.currentTimeMillis());
                    timeLabel.setText(date.toString());
                }/*from ww  w  . j  a v  a2 s.c om*/
            });
            timer.start();
            JOptionPane.showMessageDialog(null, timeLabel);
        }
    });
}