List of usage examples for javax.swing Timer start
public void start()
Timer
, causing it to start sending action events to its listeners. From source file:MainClass.java
public MainClass() { super("Progress Monitor Demo"); setSize(250, 100);//www . j a v a 2 s. c o m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Timer timer = new Timer(500, this); timer.start(); setVisible(true); }
From source file:Main.java
public Main() { setSize(250, 100);/*from w ww. ja v a 2 s. c o m*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pbar = new ProgressMonitor(null, "Monitoring Progress", "Initializing . . .", 0, 100); // Fire a timer every once in a while to update the progress. Timer timer = new Timer(500, this); timer.start(); setVisible(true); }
From source file:ProgressMonitorExample.java
public ProgressMonitorExample() { super("Progress Monitor Demo"); setSize(250, 100);//from w w w .j a va 2 s .c o m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pbar = new ProgressMonitor(null, "Monitoring Progress", "Initializing . . .", 0, 100); // Fire a timer every once in a while to update the progress. Timer timer = new Timer(500, this); timer.start(); setVisible(true); }
From source file:ColorDifference.java
/** Creates a new instance of ColorDifference */ public ColorDifference() { Timer timer = new Timer(1000, this); timer.start(); setPreferredSize(new Dimension(300, 200)); }
From source file:Main.java
/** * Creates an animation to fade the dialog opacity from 0 to 1, wait at 1 * and then fade to 0 and dispose.// w ww . j av a 2 s. com * * @param dialog the dialog to display * @param delay the delay in ms before starting and between each change * @param incrementSize the increment size * @param displayTime the time in ms the dialog is fully visible */ public static void fadeInAndOut(final JDialog dialog, final int delay, final float incrementSize, final int displayTime) { final Timer timer = new Timer(delay, null); timer.setRepeats(true); timer.addActionListener(new ActionListener() { private float opacity = 0; private boolean displayed = false; @Override public void actionPerformed(ActionEvent e) { if (!displayed) { opacity += incrementSize; dialog.setOpacity(Math.min(opacity, 1)); // requires java 1.7 if (opacity >= 1) { timer.setDelay(displayTime); displayed = true; } } else { timer.setDelay(delay); opacity -= incrementSize; dialog.setOpacity(Math.max(opacity, 0)); // requires java 1.7 if (opacity < 0) { timer.stop(); dialog.dispose(); } } } }); dialog.setOpacity(0); // requires java 1.7 timer.start(); dialog.setVisible(true); }
From source file:uk.co.petertribble.jkstat.demo.JLoadChart.java
/** * A standalone demo charting load averages. *//* w ww.j a va2s . c o m*/ public JLoadChart() { super("JLoadChart"); jkstat = new NativeJKstat(); int maxage = 600000; String lavetext = KstatResources.getString("LOAD.AVERAGE.TEXT"); ts1 = new TimeSeries("1min " + lavetext); ts1.setMaximumItemAge(maxage); ts5 = new TimeSeries("5min " + lavetext); ts5.setMaximumItemAge(maxage); ts15 = new TimeSeries("15min " + lavetext); ts15.setMaximumItemAge(maxage); updateAccessory(); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(ts1); dataset.addSeries(ts5); dataset.addSeries(ts15); JFreeChart chart = ChartFactory.createTimeSeriesChart(lavetext, KstatResources.getString("CHART.TIME"), KstatResources.getString("LOAD.LOAD.TEXT"), dataset, true, true, false); XYPlot xyplot = chart.getXYPlot(); NumberAxis loadaxis = new NumberAxis(KstatResources.getString("LOAD.LOAD.TEXT")); loadaxis.setAutoRange(true); loadaxis.setAutoRangeIncludesZero(true); xyplot.setRangeAxis(loadaxis); DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME")); daxis.setAutoRange(true); daxis.setFixedAutoRange(maxage); xyplot.setDomainAxis(daxis); addWindowListener(new winExit()); setContentPane(new ChartPanel(chart)); JMenuBar jm = new JMenuBar(); JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT")); jme.setMnemonic(KeyEvent.VK_F); exitItem = new JMenuItem(KstatResources.getString("FILE.EXIT.TEXT"), KeyEvent.VK_X); exitItem.addActionListener(this); jme.add(exitItem); jm.add(jme); setJMenuBar(jm); pack(); setVisible(true); Timer timer = new Timer(5000, this); timer.start(); }
From source file:com.github.pemapmodder.pocketminegui.gui.server.ConsolePanel.java
public ConsolePanel(ServerMainActivity activity) { this.activity = activity; setLayout(new GridBagLayout()); setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 10)); title = new JLabel("PocketMine-MP"); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.HORIZONTAL; c.weighty = 0.1;/*from w w w . j a va 2 s . c om*/ add(title, c); stdout = new JEditorPane(); stdout.setContentType("text/html"); stdout.setText("<html><body style='font-family: monospace; color: #FFFFFF;'><p id='p'></p></body></html>"); doc = (HTMLDocument) stdout.getDocument(); para = doc.getElement("p"); // stdout.setEditable(false); // People NEED to see this to feel happy stdout.setForeground(Color.WHITE); stdout.setBackground(Color.BLACK); Style style = doc.getStyleSheet().addStyle(null, null); // style.addAttribute(StyleConstants.Foreground, Color.WHITE); // style.addAttribute(StyleConstants.Background, Color.RED); doc.setParagraphAttributes(para.getStartOffset(), 1, style, true); stdout.setBorder(BorderFactory.createDashedBorder(new Color(0x80, 0x80, 0x80))); c.gridy = 1; c.weightx = 0.9; c.weighty = 0.9; c.weighty = 0.6; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTH; add(stdout, c); Timer timer = new Timer(50, e -> updateConsole()); timer.start(); }
From source file:org.jfree.chart.demo.ChartTiming2.java
/** * Runs the test.// w ww. j a va 2s . c om */ 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:Main.java
public MyCanvas() { Timer timer = new Timer(30, new ActionListener() { public void actionPerformed(ActionEvent e) { x1 += 2;/* w ww . j a va 2 s. c om*/ x2 += 2; repaint(); } }); timer.start(); }
From source file:org.jfree.chart.demo.ChartTiming1.java
/** * Runs the timing./* w ww .j a va2 s . 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"); }