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:org.jfree.chart.demo.ChartTiming4.java

/**
 * Runs the test./*w  w w  . j  a  v a  2  s.  c o m*/
 */
public void run() {

    this.finished = false;

    // create a dataset...
    populateData();

    // create a fast scatter chart...
    final Plot plot = new FastScatterPlot(this.data, new NumberAxis("X"), new NumberAxis("Y"));
    final JFreeChart chart = new JFreeChart("Fast Scatter Plot Timing", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);

    final BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB);
    final Graphics2D g2 = image.createGraphics();
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 400, 300);

    // set up the timer...
    final Timer timer = new Timer(10000, this);
    timer.setRepeats(false);
    int count = 0;
    timer.start();
    while (!this.finished) {
        chart.draw(g2, chartArea, null, null);
        System.out.println("Charts drawn..." + count);
        if (!this.finished) {
            count++;
        }
    }
    System.out.println("DONE");

}

From source file:org.jfree.chart.demo.ChartTiming3.java

/**
 * Runs the test.// w ww . ja v  a 2s .  c  o  m
 */
public void run() {

    this.finished = false;

    // create a dataset...
    final XYSeries series = new XYSeries("Random Data");
    for (int i = 0; i < 1440; i++) {
        final double x = Math.random();
        final double y = Math.random();
        series.add(x, y);
    }
    final XYDataset data = new XYSeriesCollection(series);

    // create a scatter chart...
    final boolean withLegend = true;
    final JFreeChart chart = ChartFactory.createScatterPlot("Scatter plot timing", "X", "Y", data,
            PlotOrientation.VERTICAL, withLegend, false, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDotRenderer());

    final BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB);
    final Graphics2D g2 = image.createGraphics();
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 400, 300);

    // set up the timer...
    final Timer timer = new Timer(10000, this);
    timer.setRepeats(false);
    int count = 0;
    timer.start();
    while (!this.finished) {
        chart.draw(g2, chartArea, null, null);
        System.out.println("Charts drawn..." + count);
        if (!this.finished) {
            count++;
        }
    }
    System.out.println("DONE");

}

From source file:Main.java

public ClockPane() {
    setLayout(new BorderLayout());
    tickTock();/*  w  w  w . jav  a 2  s .c  o  m*/
    add(clock);
    Timer timer = new Timer(500, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tickTock();
        }
    });
    timer.setRepeats(true);
    timer.setCoalesce(true);
    timer.setInitialDelay(0);
    timer.start();
}

From source file:Main.java

public StringPanel() {
    for (int i = 1; i <= 100; i++) {
        list.add("Word " + i);
    }//  w w  w .  j  a va 2 s .c  o m

    word = list.get(0);

    Timer timer = new Timer(500, e -> {
        int rand = random.nextInt(list.size());
        word = list.get(rand);
        x = random.nextInt(D_W - wordWidth);
        y = random.nextInt(D_H) + wordHeight;

        repaint();
    });
    timer.start();
}

From source file:Main.java

public BlinkPane() {
    label = new JLabel("Hello");
    setLayout(new GridBagLayout());

    add(label);//from  ww  w.j a  v  a  2s  . c om
    Timer timer = new Timer(1000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            on = !on;
            repaint();
        }
    });
    timer.setRepeats(true);
    timer.setCoalesce(true);
    timer.start();
}

From source file:WindowEventDemo.java

public void windowClosing(WindowEvent e) {
    displayMessage("WindowListener method called: windowClosing.");

    //A pause so user can see the message before
    //the window actually closes.
    ActionListener task = new ActionListener() {
        boolean alreadyDisposed = false;

        public void actionPerformed(ActionEvent e) {
            if (!alreadyDisposed) {
                alreadyDisposed = true;//w w w  . ja  va 2s.com
                frame.dispose();
            } else { //make sure the program exits
                System.exit(0);
            }
        }
    };
    Timer timer = new Timer(500, task); //fire every half second
    timer.setInitialDelay(2000); //first delay 2 seconds
    timer.start();
}

From source file:me.mayo.telnetkek.ConnectionManager.java

public void sendDelayedCommand(final String text, final boolean verbose, final int delay) {
    final Timer timer = new Timer(delay, event -> sendCommand(text, verbose));
    timer.setRepeats(false);/*from   ww w.  j a  va 2 s.c  o m*/
    timer.start();
}

From source file:llc.rockford.webcast.EC2Driver.java

public EC2Driver(String[] args) {
    parseCommandLine(args);/*  www .  j  a  va  2 s  .com*/
    createAndShowGUI();
    applicationState = new ApplicationState(this);

    new InitializeWorker(ec2Handle.getEc2Handle(), applicationState).execute();

    Timer timer = new Timer(5000, this);
    timer.setInitialDelay(3000);
    timer.start();

    broadcaster = new StreamBroadcaster(amazonProperties);

    // add shut down hooks to terminate amazon EC2 instance
    // to prevent over billing
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            new TerminateInstanceWorker(ec2Handle.getEc2Handle(), applicationState, amazonProperties).execute();
        }
    });

}

From source file:events.WindowEventDemo.java

public void windowClosing(WindowEvent e) {
    displayMessage("WindowListener method called: windowClosing.");
    //A pause so user can see the message before
    //the window actually closes.
    ActionListener task = new ActionListener() {
        boolean alreadyDisposed = false;

        public void actionPerformed(ActionEvent e) {
            if (frame.isDisplayable()) {
                alreadyDisposed = true;//w ww.  j  a v a2  s.com
                frame.dispose();
            }
        }
    };
    Timer timer = new Timer(500, task); //fire every half second
    timer.setInitialDelay(2000); //first delay 2 seconds
    timer.setRepeats(false);
    timer.start();
}

From source file:Main.java

public BackgroundPane() {
    try {/*from w  ww.  j  a v a 2  s.c o  m*/
        bg = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    Timer timer = new Timer(40, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            yOffset += yDelta;
            if (yOffset > getHeight()) {
                yOffset = 0;
            }
            repaint();
        }
    });
    timer.start();
}