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

public Main() {
    for (int i = 0; i < panels.length; i++) {
        final String[] labels = new String[] { "0", "1" };
        final Random rand = new Random();
        int index = rand.nextInt(labels.length);
        String randomTitle = labels[index];
        final JLabel label = new JLabel(randomTitle, JLabel.CENTER);
        Timer lblt = new Timer(00, new ActionListener() {
            @Override//w ww  .  j a  va2s  .  c  o m
            public void actionPerformed(ActionEvent ae) {
                label.setText(labels[rand.nextInt(labels.length)]);
            }
        });
        lblt.setRepeats(true);
        lblt.start();
        label.setForeground(Color.green);
        label.setVerticalAlignment(JLabel.CENTER);
        panels[i] = new JPanel();
        panels[i].setBackground(Color.BLACK);
        panels[i].add(label);
        frame.getContentPane().add(panels[i]);
    }
    frame.setLayout(new GridLayout(grid, grid));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
    frame.setVisible(true);

    ActionListener action = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < panels.length; i++) {
                Color mix = new Color(255, 255, 255);
                Random random = new Random();
                int r = random.nextInt(255);
                int g = random.nextInt(255);
                int b = random.nextInt(255);

                if (mix != null) {
                    r = (r + mix.getRed()) / 2;
                    g = (g + mix.getGreen()) / 2;
                    b = (b + mix.getBlue()) / 2;
                }
                Color color = new Color(r, g, b);
                panels[i].setBackground(color);
            }
        }
    };

    t = new Timer(00, action);
    t.setRepeats(true);
    t.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 (frame.isDisplayable()) {
                alreadyDisposed = true;/* w  ww.j av  a2  s  .c  o  m*/
                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:org.uncommons.watchmaker.swing.evolutionmonitor.JVMView.java

JVMView() {
    super(new BorderLayout());
    double maxMemory = (double) memoryBean.getHeapMemoryUsage().getMax() / MEGABYTE;

    ChartPanel heapPanel = new ChartPanel(createHeapChart(maxMemory), false, // Properties
            true, // Save
            true, // Print
            false, // Zoom
            true); // Tooltips
    heapPanel.setMouseZoomable(false);//from   www  . j a v  a  2  s .  c  om
    add(heapPanel, BorderLayout.CENTER);
    add(createControls(), BorderLayout.SOUTH);

    Timer timer = new Timer(5000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addMemoryDataPoint();
        }
    });

    // Plot start values.
    addMemoryDataPoint();

    timer.start();
}

From source file:SplashScreen.java

/**
 * Open the splash screen and keep it open for the specified duration
 * or until close() is called explicitly.
 *//*from w ww  . j  a  va 2  s  . c  o m*/
public void open(int nMilliseconds) {
    if (image_ == null)
        return;

    Timer timer = new Timer(Integer.MAX_VALUE, new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            ((Timer) event.getSource()).stop();
            close();
        };
    });

    timer.setInitialDelay(nMilliseconds);
    timer.start();

    setBounds(x_, y_, width_, height_);
    setVisible(true);
}

From source file:es.emergya.ui.gis.popups.GPSDialog.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(i18n.getString("window.gps.button.actualizar"))) {
        last_bandejaSalida = send();//from w  ww.j av  a 2  s  .  c o m
        log.info("bandeja de salida: " + last_bandejaSalida);

        if (last_bandejaSalida == null) {
            return;
        }

        final JButton request = ((JButton) e.getSource());

        request.setEnabled(false);
        progressIcon.setIcon(iconEnviando);
        notification.setForeground(Color.WHITE);

        SolicitudGPSActionListener listener = new SolicitudGPSActionListener(last_bandejaSalida);
        Timer t = new Timer(1000, listener);

        listener.setTimer(t);
        t.start();
    }

    if (e.getActionCommand().equals(i18n.getString("Buttons.cancel"))) {
        if (last_bandejaSalida != null) {
            MessageGenerator.remove(last_bandejaSalida.getId());
        }

        last_bandejaSalida = null;
        dispose();
    }
}

From source file:Main.java

public Main() {
    frame.setSize(600, 600);//from  www  .  ja  v a 2s. c o  m
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setVisible(true);
    frame.setExtendedState(JFrame.ICONIFIED);
    Timer t = new Timer(3000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    frame.setExtendedState(JFrame.NORMAL);
                }
            });
        }
    });
    t.setRepeats(false);
    t.start();
}

From source file:cz.alej.michalik.totp.client.OtpPanel.java

/**
 * Pid jeden panel se zznamem//from w  w w  .jav a  2s.  c  o  m
 * 
 * @param raw_data
 *            Data z Properties
 * @param p
 *            Properties
 * @param index
 *            Index zznamu - pro vymazn
 */
public OtpPanel(String raw_data, final Properties p, final int index) {
    // Data jsou oddlena stednkem
    final String[] data = raw_data.split(";");

    // this.setBackground(App.COLOR);
    this.setLayout(new GridBagLayout());
    // Mkov rozloen prvk
    GridBagConstraints c = new GridBagConstraints();
    this.setMaximumSize(new Dimension(Integer.MAX_VALUE, 100));

    // Tla?tko pro zkoprovn hesla
    final JButton passPanel = new JButton("");
    passPanel.setFont(passPanel.getFont().deriveFont(App.FONT_SIZE));
    passPanel.setBackground(App.COLOR);
    // Zabere celou ku
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 100;
    this.add(passPanel, c);
    passPanel.setText(data[0]);

    // Tla?tko pro smazn
    JButton delete = new JButton("X");
    try {
        String path = "/material-design-icons/action/drawable-xhdpi/ic_delete_black_24dp.png";
        Image img = ImageIO.read(App.class.getResource(path));
        delete.setIcon(new ImageIcon(img));
        delete.setText("");
    } catch (Exception e) {
        System.out.println("Icon not found");
    }
    delete.setFont(delete.getFont().deriveFont(App.FONT_SIZE));
    delete.setBackground(App.COLOR);
    // Zabere kousek vpravo
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.5;
    c.anchor = GridBagConstraints.EAST;
    this.add(delete, c);

    // Akce pro vytvoen a zkoprovn hesla do schrnky
    passPanel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Generuji kod pro " + data[1]);
            System.out.println(new Base32().decode(data[1].getBytes()).length);
            clip.set(new TOTP(new Base32().decode(data[1].getBytes())).toString());
            System.out.printf("Kd pro %s je ve schrnce\n", data[0]);
            passPanel.setText("Zkoprovno");
            // Zobraz zprvu na 1 vteinu
            int time = 1000;
            // Animace zobrazen zprvy po zkoprovn
            final Timer t = new Timer(time, new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    passPanel.setText(data[0]);
                }
            });
            t.start();
            t.setRepeats(false);
        }
    });

    // Akce pro smazn panelu a uloen zmn
    delete.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.printf("Odstrann %s s indexem %d\n", data[0], index);
            p.remove(String.valueOf(index));
            App.saveProperties();
            App.loadProperties();
        }
    });

}

From source file:subterranean.crimson.server.graphics.graphs.LineChart.java

public LineChart() {

    super(new BorderLayout());

    final TimeSeriesCollection dataset = new TimeSeriesCollection(this.s1);
    final JFreeChart chart = createChart(dataset);

    Timer timer = new Timer(900, this);
    timer.setInitialDelay(0);/* w w  w. ja va2 s.  c om*/

    // Sets background color of chart
    chart.setBackgroundPaint(Color.LIGHT_GRAY);

    // Created Chartpanel for chart area
    final ChartPanel chartPanel = new ChartPanel(chart);

    // Added chartpanel to main panel
    add(chartPanel);

    timer.start();

}

From source file:Main.java

public TestPane() {
    setLayout(new GridBagLayout());
    label = new JLabel();
    add(label);/*from  w  ww .  j a v  a  2  s  . c  o  m*/
    Timer timer = new Timer(1000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String labelText = label.getText();
            labelText += text.charAt(charIndex);
            label.setText(labelText);
            charIndex++;
            if (charIndex >= text.length()) {
                ((Timer) e.getSource()).stop();
            }
        }
    });
    timer.start();
}

From source file:es.emergya.ui.gis.popups.SDSDialog.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(i18n.getString("Buttons.send"))) {
        bandejaSalida = send();//  ww  w  . j a v a2 s.c o  m

        if (bandejaSalida == null) {
            return;
        }

        notification.setForeground(Color.WHITE);
        progressIcon.setIcon(iconEnviando);
        send.setEnabled(false);
        sds.setEnabled(false);

        SendActionListener listener = new SendActionListener(bandejaSalida);
        final Timer t = new Timer(1000, listener);

        listener.setTimer(t);
        t.start();
    } else if (e.getActionCommand().equals(i18n.getString("Buttons.cancel"))) {
        if (bandejaSalida != null) {
            MessageGenerator.remove(bandejaSalida.getId());
        }

        bandejaSalida = null;
        dispose();
    }
}