Example usage for javax.swing Timer setRepeats

List of usage examples for javax.swing Timer setRepeats

Introduction

In this page you can find the example usage for javax.swing Timer setRepeats.

Prototype

public void setRepeats(boolean flag) 

Source Link

Document

If flag is false, instructs the Timer to send only one action event to its listeners.

Usage

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);
    timer.start();//from  w  ww  .j  a v  a  2 s .  c  om
}

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 a 2s  . 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: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/*from   w w  w  .ja v a2  s .  com*/
            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 w w .  j a v 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:TapTapTap.java

public void createUI() {
    JFrame f = new JFrame("TapTapTap");

    final WaitLayerUI layerUI = new WaitLayerUI();
    JPanel panel = createPanel();
    JLayer<JPanel> jlayer = new JLayer<JPanel>(panel, layerUI);

    final Timer stopper = new Timer(4000, new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            layerUI.stop();/*from   w w w  . ja  va2s.c o m*/
        }
    });
    stopper.setRepeats(false);

    mOrderButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            layerUI.start();
            if (!stopper.isRunning()) {
                stopper.start();
            }
        }
    });

    f.add(jlayer);

    f.setSize(300, 200);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public Main() {
    frame.setSize(600, 600);/*from  w  w w.  j  a  v a2  s.c om*/
    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 ww  .  j a v  a2 s .  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:eu.delving.sip.model.ReportFileModel.java

public ReportFileModel(final SipModel sipModel) {
    this.sipModel = sipModel;
    Timer timer = new Timer(1000, new ActionListener() {
        @Override/*  w  ww  .  j  av a  2 s  .  c  o m*/
        public void actionPerformed(ActionEvent e) {
            for (ReportFile reportFile : reportFiles) {
                List<ReportFile.Rec> fetch = reportFile.prepareFetch();
                if (!fetch.isEmpty()) {
                    sipModel.exec(reportFile.fetchRecords(fetch, sipModel.getFeedback()));
                }
                reportFile.maintainCache();
            }
        }
    });
    timer.setRepeats(true);
    timer.start();
}

From source file:net.sf.jabref.gui.maintable.MainTableSelectionListener.java

private void updatePreview(final BibEntry toShow, final boolean changedPreview, int repeats) {
    if (workingOnPreview) {
        if (repeats > 0) {
            return; // We've already waited once. Give up on this selection.
        }//  w w w  .j a  v  a  2  s. c o  m
        Timer t = new Timer(50, actionEvent -> updatePreview(toShow, changedPreview, 1));
        t.setRepeats(false);
        t.start();
        return;
    }
    EventList<BibEntry> list = table.getSelected();
    // Check if the entry to preview is still selected:
    if ((list.size() != 1) || (list.get(0) != toShow)) {
        return;
    }
    final BasePanelMode mode = panel.getMode();
    workingOnPreview = true;
    SwingUtilities.invokeLater(() -> {
        preview.setEntry(toShow);

        // If nothing was already shown, set the preview and move the separator:
        if (changedPreview || (mode == BasePanelMode.SHOWING_NOTHING)) {
            panel.showPreview(preview);
            panel.adjustSplitter();
        }
        workingOnPreview = false;
    });
}

From source file:com.qframework.core.ServerkoParse.java

public void execScript(final String respdata, int delay) {
    Timer t = new javax.swing.Timer(delay, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            execScript(respdata);//w ww .j  av a2  s.  c o m
        }
    });
    t.setRepeats(false);
    t.start();
}