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:Main.java
public TestPane() { Timer timer = new Timer(40, new ActionListener() { @Override/*from w w w .java2 s .com*/ public void actionPerformed(ActionEvent e) { x += xDelta; if (x + (radius * 2) > getWidth()) { x = getWidth() - (radius * 2); xDelta *= -1; } else if (x < 0) { x = 0; xDelta *= -1; } repaint(); } }); 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 . j av a 2 s . 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() { JPanel panel = new JPanel(); BoxLayout boxLayout = new BoxLayout(panel, BoxLayout.PAGE_AXIS); panel.setLayout(boxLayout);//from w ww .jav a 2s. co m for (int i = 0; i < 40; i++) { panel.add(new JButton("Button " + i)); } buttons = panel.getComponents(); activeComponent = buttons[index]; final JScrollPane scroll = new JScrollPane(panel); Timer timer = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent e) { ((JButton) activeComponent).setForeground(Color.BLACK); if (index >= buttons.length - 1) { index = 0; } else { index++; } activeComponent = buttons[index]; ((JButton) activeComponent).setForeground(Color.red); setView(scroll, activeComponent); System.out.println(((JButton) activeComponent).getActionCommand()); } }); timer.start(); scroll.setPreferredSize(new Dimension(200, 300)); JFrame frame = new JFrame(); frame.add(scroll); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
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//from ww w . j a va 2 s . c om 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. }/*from w w w. j a va 2s.co 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 w w .ja va 2 s . c o m*/ } }); t.setRepeats(false); t.start(); }
From source file:com.qframework.core.ServerkoParse.java
public void loadModule(final String resptype) { Timer t = new javax.swing.Timer(0, new ActionListener() { public void actionPerformed(ActionEvent e) { execLoadModule(resptype);/*from w ww . j a va2s . co m*/ } }); t.setRepeats(false); t.start(); }
From source file:org.micromanager.CRISP.CRISPFrame.java
private void CalibrateButton_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CalibrateButton_ActionPerformed try {/*from w ww . jav a 2 s.c om*/ core_.setProperty(CRISP_, "CRISP State", "loG_cal"); String state = ""; int counter = 0; while (!state.equals("loG_cal") && counter < 50) { state = core_.getProperty(CRISP_, "CRISP State"); Thread.sleep(100); } Double snr = new Double(core_.getProperty(CRISP_, "Signal Noise Ratio")); if (snr < 2.0) ReportingUtils.showMessage("Signal Noise Ratio is smaller than 2.0. " + "Focus on your sample, increase LED intensity and try again."); core_.setProperty(CRISP_, "CRISP State", "Dither"); String value = core_.getProperty(CRISP_, "Dither Error"); final JLabel jl = new JLabel(); final JLabel jlA = new JLabel(); final JLabel jlB = new JLabel(); final String msg1 = "Value: "; final String msg2 = "Adjust the detector lateral adjustment screw until the value is > 100 or" + "< -100 and stable."; jlA.setText(msg1); jl.setText(value); jl.setAlignmentX(JLabel.CENTER); Object[] msg = { msg1, jl, msg2 }; ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent evt) { try { jl.setText(core_.getProperty(CRISP_, "Dither Error")); } catch (Exception ex) { ReportingUtils.logError("Error while getting CRISP dither Error"); } } }; Timer timer = new Timer(100, al); timer.setInitialDelay(500); timer.start(); /*JOptionPane optionPane = new JOptionPane(new JLabel("Hello World",JLabel.CENTER)); JDialog dialog = optionPane.createDialog(""); dialog.setModal(true); dialog.setVisible(true); */ JOptionPane.showMessageDialog(null, msg, "CRISP Calibration", JOptionPane.OK_OPTION); timer.stop(); core_.setProperty(CRISP_, "CRISP State", "gain_Cal"); counter = 0; while (!state.equals("Ready") && counter < 50) { state = core_.getProperty(CRISP_, "CRISP State"); Thread.sleep(100); } // ReportingUtils.showMessage("Calibration failed. Focus, make sure that the NA variable is set correctly and try again."); } catch (Exception ex) { ReportingUtils.showMessage( "Calibration failed. Focus, make sure that the NA variable is set correctly and try again."); } }
From source file:com.qframework.core.ServerkoParse.java
public void loadModule2(final String resptype) { Timer t = new javax.swing.Timer(0, new ActionListener() { public void actionPerformed(ActionEvent e) { execLoadModule2(resptype);/* ww w . j a va 2 s . co m*/ } }); //t.setIntialDelay(delay); t.setRepeats(false); t.start(); }
From source file:com.qframework.core.ServerkoParse.java
public void loadScript(final String resptype, int time) { Timer t = new javax.swing.Timer(time, new ActionListener() { public void actionPerformed(ActionEvent e) { execLoadModule2(resptype);//from w ww .ja va2 s.c o m } }); //t.setIntialDelay(delay); t.setRepeats(false); t.start(); }