List of usage examples for javax.swing Timer setRepeats
public void setRepeats(boolean flag)
flag
is false
, instructs the Timer
to send only one action event to its listeners. From source file:Main.java
/** * Creates an animation to fade the dialog opacity from 1 to 0. *///from w w w . ja va 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
public static void runTimer(int duration, final Runnable run) { Timer t = new Timer(duration, new ActionListener() { public void actionPerformed(ActionEvent e) { run.run();/*from w ww . j a v a2 s . c o m*/ } }); t.setRepeats(false); t.start(); }
From source file:Main.java
/** * Runs the supplied class after a certain period of time, the thread * will be executed in the EDT. //from w w w . j a v a 2 s . c o m * * @param execute The runnable object whose method will be called after the * specified delay * @param after The delay in ms before the event will be called */ public static Timer invokeAfter(final Runnable execute, int after) { Timer timer = new Timer(after, new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { execute.run(); } }); timer.setRepeats(false); timer.start(); return timer; }
From source file:Main.java
private static void triggerBringToFront(final JFrame f, final int delayMS) { Timer timer = new Timer(delayMS, new ActionListener() { @Override//from w w w. j a v a2 s . c o m 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:org.jfree.chart.demo.ChartTiming2.java
/** * Runs the test./* w w w . ja va 2 s. co m*/ */ public void run() { this.finished = false; // create a dataset... final XYDataset data = new SampleXYDataset2(1, 1440); // 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:org.jfree.chart.demo.ChartTiming1.java
/** * Runs the timing./*w w w .j av a2s .co m*/ */ public void run() { this.finished = false; // create a dataset... final DefaultPieDataset data = new DefaultPieDataset(); data.setValue("One", new Double(10.3)); data.setValue("Two", new Double(8.5)); data.setValue("Three", new Double(3.9)); data.setValue("Four", new Double(3.9)); data.setValue("Five", new Double(3.9)); data.setValue("Six", new Double(3.9)); // create a pie chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createPieChart("Testing", data, withLegend, true, false); 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.ChartTiming4.java
/** * Runs the test.//w ww . j a va 2 s . co 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 . j a 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 ww.j a va 2s . 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 BlinkPane() { label = new JLabel("Hello"); setLayout(new GridBagLayout()); add(label);/*from w w w. j av a 2s .c o m*/ Timer timer = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { on = !on; repaint(); } }); timer.setRepeats(true); timer.setCoalesce(true); timer.start(); }