javax.swing.Timer#start ( )源码实例Demo

下面列出了javax.swing.Timer#start ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: btdex   文件: RotatingIcon.java
public RotatingIcon(Icon icon) {
	delegateIcon = icon;
	
	rotatingTimer = new Timer( 200, new ActionListener() {
		@Override
		public void actionPerformed( ActionEvent e ) {
			angleInDegrees = angleInDegrees + 40;
			if ( angleInDegrees == 360 ){
				angleInDegrees = 0;
			}
			
			for(DefaultTableModel model : cells.keySet()) {
				for(Point c : cells.get(model))
					model.fireTableCellUpdated(c.x, c.y);					
			}
		}
	} );
	rotatingTimer.setRepeats( false );
	rotatingTimer.start();
}
 
源代码2 项目: pumpernickel   文件: FadingPanel.java
/**
 * Animate this panel. This fades from its current state to the state after
 * the argument runnable has been performed.
 * <P>
 * This method should be called from the event dispatch thread.
 * 
 * @param r
 *            the changes to make to this panel.
 * @param duration
 *            the duration the fade should last, in milliseconds. Usually
 *            250 is a reasonable number.
 */
public void animateStates(Runnable r, final long duration) {
	captureStates(r);
	setProgress(0);
	final long start = System.currentTimeMillis();
	ActionListener actionListener = new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			long current = System.currentTimeMillis() - start;
			float f = ((float) current) / ((float) duration);
			if (f > 1)
				f = 1;
			setProgress(f);
			if (f == 1) {
				((Timer) e.getSource()).stop();
			}
		}
	};
	Timer timer = new Timer(40, actionListener);
	timer.start();
}
 
源代码3 项目: marathonv5   文件: TumbleItem.java
public void init() {
    loadAppletParameters();

    // Execute a job on the event-dispatching thread:
    // creating this applet's GUI.
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                createGUI();
            }
        });
    } catch (Exception e) {
        System.err.println("createGUI didn't successfully complete");
    }

    // Set up timer to drive animation events.
    timer = new Timer(speed, this);
    timer.setInitialDelay(pause);
    timer.start();

    // Start loading the images in the background.
    worker.execute();
}
 
源代码4 项目: MogwaiERDesignerNG   文件: FadeInFadeOutHelper.java
public FadeInFadeOutHelper() {
    componentToHighlightTimer = new Timer(50, e -> {

        if (componentToHighlightFadeOut) {
            if (componentToHighlightPosition > 0) {
                componentToHighlightPosition -= 40;
            } else {
                componentToHighlightFadeOut = false;
                componentToHighlight = componentToHighlightNext;
            }
        } else {
            if (componentToHighlightNext != null) {
                componentToHighlight = componentToHighlightNext;
                componentToHighlightNext = null;
            }
            if (componentToHighlight != null) {
                Dimension theSize = componentToHighlight.getSize();
                if (componentToHighlightPosition < theSize.width + 10) {
                    int theStep = theSize.width + 10 - componentToHighlightPosition;
                    if (theStep > 40) {
                        theStep = 40;
                    }
                    componentToHighlightPosition += theStep;
                } else {
                    componentToHighlightTimer.stop();
                }
            } else {
                componentToHighlightTimer.stop();
            }
        }

        doRepaint();
    });
    componentToHighlightWaitTimer = new Timer(1000, e -> componentToHighlightTimer.start());
    componentToHighlightWaitTimer.setRepeats(false);
}
 
源代码5 项目: chipster   文件: TaskExecutor.java
private void setupTimeoutTimer(Task task, int timeout) {
	// setup timeout checker if needed
	if (timeout != -1) {
		// we'll have to timeout this task
		Timer timer = new Timer(timeout, new TimeoutListener(task));
		timer.setRepeats(false);
		timer.start();
	}
}
 
源代码6 项目: dctb-utfpr-2018-1   文件: Login.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    jButton1.setVisible(false);
    jProgressBar1.setVisible(true);
    
    tempo = new Timer(100, new progresso(jProgressBar1, tempo));
    tempo.start();
}
 
源代码7 项目: openjdk-jdk9   文件: Test6559154.java
public void run() {
    Timer timer = new Timer(1000, this);
    timer.setRepeats(false);
    timer.start();

    JColorChooser chooser = new JColorChooser();
    setEnabledRecursive(chooser, false);

    this.dialog = new JDialog();
    this.dialog.add(chooser);
    this.dialog.setVisible(true);
}
 
源代码8 项目: visualvm   文件: HostOverviewView.java
protected DataViewComponent createComponent() {
    GlobalPreferences preferences = GlobalPreferences.sharedInstance();
    int chartCache = preferences.getMonitoredHostCache() * 60 /
                     preferences.getMonitoredHostPoll();

    DataViewComponent dvc = new DataViewComponent(
            new MasterViewSupport((Host)getDataSource()).getMasterView(),
            new DataViewComponent.MasterViewConfiguration(false));

    boolean cpuSupported = hostOverview.getSystemLoadAverage() >= 0;
    final CpuLoadViewSupport cpuLoadViewSupport = new CpuLoadViewSupport(hostOverview, cpuSupported, chartCache);
    dvc.configureDetailsArea(new DataViewComponent.DetailsAreaConfiguration(NbBundle.getMessage(HostOverviewView.class, "LBL_CPU"), true), DataViewComponent.TOP_LEFT); // NOI18N
    dvc.addDetailsView(cpuLoadViewSupport.getDetailsView(), DataViewComponent.TOP_LEFT);
    if (!cpuSupported) dvc.hideDetailsArea(DataViewComponent.TOP_LEFT);

    final PhysicalMemoryViewSupport physicalMemoryViewSupport = new PhysicalMemoryViewSupport(chartCache);
    dvc.configureDetailsArea(new DataViewComponent.DetailsAreaConfiguration(NbBundle.getMessage(HostOverviewView.class, "LBL_Memory"), true), DataViewComponent.TOP_RIGHT); // NOI18N
    dvc.addDetailsView(physicalMemoryViewSupport.getDetailsView(), DataViewComponent.TOP_RIGHT);

    final SwapMemoryViewSupport swapMemoryViewSupport = new SwapMemoryViewSupport(chartCache);
    dvc.addDetailsView(swapMemoryViewSupport.getDetailsView(), DataViewComponent.TOP_RIGHT);

    timer = new Timer(2000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            final long time = System.currentTimeMillis();
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    cpuLoadViewSupport.refresh(hostOverview, time);
                    physicalMemoryViewSupport.refresh(hostOverview, time);
                    swapMemoryViewSupport.refresh(hostOverview, time);
                }
            });
        }
    });
    timer.setInitialDelay(800);
    timer.start();
    ((Host)getDataSource()).notifyWhenRemoved(this);
    
    return dvc;
}
 
源代码9 项目: Course_Generator   文件: frmAbout.java
/**
 * Creates new form DialogAbout
 */
public frmAbout(java.awt.Frame parent, boolean modal, boolean autoclose, String version) {
	super(parent, modal);

	bundle = java.util.ResourceBundle.getBundle("course_generator/Bundle");
	initComponents();

	lbVersion.setText("V" + version);

	if (autoclose) {
		Timer timer = new Timer(2000, new MyTimerActionListener());
		timer.start();
	}
}
 
源代码10 项目: Java-MP3-player   文件: JPanelsSliding.java
public void nextSlidPanel(int SpeedPanel, int TimeSpeed,Component ShowPanel, direct DirectionMove) { 
    if (!ShowPanel.getName().equals(getCurrentComponentShow(this))) { 
        Component currentComp = getCurrentComponent(this);           
        ShowPanel.setVisible(true);                     
        JPanelSlidingListener sl = new JPanelSlidingListener(SpeedPanel, currentComp, ShowPanel, DirectionMove);
        Timer t = new Timer(TimeSpeed, sl);            
        sl.timer = t;           
        t.start();           
    }   
    refresh();
}
 
源代码11 项目: jitsi   文件: HistoryWindow.java
/**
 * Handles the ProgressEvent triggered from the history when processing
 * a query.
 * @param evt the <tt>ProgressEvent</tt> that notified us
 */
public void progressChanged(ProgressEvent evt)
{
    int progress = evt.getProgress();

    if((lastProgress != progress)
            && evt.getStartDate() == null
            || evt.getStartDate() != ignoreProgressDate)
    {
        this.progressBar.setValue(progress);

        if(progressBar.getPercentComplete() == 1.0)
        {
            // Wait 1 sec and remove the progress bar from the main panel.
            Timer progressBarTimer = new Timer(1 * 1000, null);

            progressBarTimer.setRepeats(false);
            progressBarTimer.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e)
                {
                    mainPanel.remove(progressBar);
                    mainPanel.add(readyLabel, BorderLayout.SOUTH);
                    mainPanel.revalidate();
                    mainPanel.repaint();
                    progressBar.setValue(0);
                }
            });
            progressBarTimer.start();
        }

        lastProgress = progress;
    }
}
 
源代码12 项目: tracker   文件: ExportZipDialog.java
/**
 * Offers to open a newly saved zip file.
 *
 * @param path the path to the zip file
 */
private void openZip(final String path) {
  Runnable runner1 = new Runnable() {
  	public void run() {
    	int response = javax.swing.JOptionPane.showConfirmDialog(
    			frame,	    			
    			TrackerRes.getString("ZipResourceDialog.Complete.Message1") //$NON-NLS-1$ 
    			+" \""+XML.getName(path)+"\".\n" //$NON-NLS-1$ //$NON-NLS-2$
    			+TrackerRes.getString("ZipResourceDialog.Complete.Message2"), //$NON-NLS-1$ 
    			TrackerRes.getString("ZipResourceDialog.Complete.Title"), //$NON-NLS-1$ 
    			javax.swing.JOptionPane.YES_NO_OPTION, 
    			javax.swing.JOptionPane.QUESTION_MESSAGE);
    	if (response == javax.swing.JOptionPane.YES_OPTION) {
    		frame.loadedFiles.remove(path);
        Runnable runner = new Runnable() {
        	public void run() {
        		// open the TRZ in a Tracker tab
        		TrackerIO.open(new File(path), frame);
        		// open the TRZ in the Library Browser
  	      	frame.getLibraryBrowser().open(path);
  	      	frame.getLibraryBrowser().setVisible(true);
  	        Timer timer = new Timer(1000, new ActionListener() {
  	          public void actionPerformed(ActionEvent e) {
  	          	LibraryTreePanel treePanel = frame.getLibraryBrowser().getSelectedTreePanel();
  	          	if (treePanel!=null) {
  		    				treePanel.refreshSelectedNode();
  	          	}
  	          }
  	        });
  	        timer.setRepeats(false);
  	        timer.start();
        	}
        };
        SwingUtilities.invokeLater(runner);
    	}
  	}
  };
  SwingUtilities.invokeLater(runner1);  	
}
 
源代码13 项目: hottub   文件: Test6559154.java
public void run() {
    Timer timer = new Timer(1000, this);
    timer.setRepeats(false);
    timer.start();

    JColorChooser chooser = new JColorChooser();
    setEnabledRecursive(chooser, false);

    this.dialog = new JDialog();
    this.dialog.add(chooser);
    this.dialog.setVisible(true);
}
 
源代码14 项目: tn5250j   文件: SessionBean.java
private void doVisibility()
{
  if (!isVisible() && (visibilityInterval > 0))
  {
    Timer t = new Timer(visibilityInterval, new DoVisible());
    t.setRepeats(false);
    t.start();
  }
  else if (!isVisible())
  {
    new DoVisible().run();
  }
}
 
源代码15 项目: pumpernickel   文件: QOptionPane.java
private JComponent createDebugPanel() {
	BufferedImage img = (BufferedImage) getClientProperty("debug.ghost.image");

	if (img == null)
		return this;

	final CardLayout cardLayout = new CardLayout();
	final JPanel panel = new JPanel(cardLayout);

	JPanel imagePanel = new JPanel();
	imagePanel.setUI(new PanelImageUI(img));

	JPanel paneWrapper = new JPanel(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.NONE;
	c.gridx = 0;
	c.gridy = 0;
	c.weightx = 1;
	c.weighty = 1;
	paneWrapper.add(this, c);

	panel.add(paneWrapper, "real");
	panel.add(imagePanel, "debug");

	Timer timer = new Timer(2000, new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			String mode = (System.currentTimeMillis() % 4000) > 2000 ? "real"
					: "debug";
			cardLayout.show(panel, mode);
		}
	});
	timer.start();

	return panel;
}
 
源代码16 项目: gate-core   文件: TextualDocumentView.java
@Override
protected void initGUI() {
  // textView = new JEditorPane();
  // textView.setContentType("text/plain");
  // textView.setEditorKit(new RawEditorKit());

  textView = new JTextArea();
  textView.setAutoscrolls(false);
  textView.setLineWrap(true);
  textView.setWrapStyleWord(true);
  // the selection is hidden when the focus is lost for some system
  // like Linux, so we make sure it stays
  // it is needed when doing a selection in the search textfield
  textView.setCaret(new PermanentSelectionCaret());
  scroller = new JScrollPane(textView);

  textView.setText(document.getContent().toString());
  textView.getDocument().addDocumentListener(swingDocListener);
  // display and put the caret at the beginning of the file
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      try {
        if(textView.modelToView(0) != null) {
          textView.scrollRectToVisible(textView.modelToView(0));
        }
        textView.select(0, 0);
        textView.requestFocus();
      } catch(BadLocationException e) {
        e.printStackTrace();
      }
    }
  });
  // contentPane = new JPanel(new BorderLayout());
  // contentPane.add(scroller, BorderLayout.CENTER);

  // //get a pointer to the annotation list view used to display
  // //the highlighted annotations
  // Iterator horizViewsIter = owner.getHorizontalViews().iterator();
  // while(annotationListView == null && horizViewsIter.hasNext()){
  // DocumentView aView = (DocumentView)horizViewsIter.next();
  // if(aView instanceof AnnotationListView)
  // annotationListView = (AnnotationListView)aView;
  // }
  highlightsMinder = new Timer(BLINK_DELAY, new UpdateHighlightsAction());
  highlightsMinder.setInitialDelay(HIGHLIGHT_DELAY);
  highlightsMinder.setDelay(BLINK_DELAY);
  highlightsMinder.setRepeats(true);
  highlightsMinder.setCoalesce(true);
  highlightsMinder.start();

  // blinker = new Timer(this.getClass().getCanonicalName() +
  // "_blink_timer",
  // true);
  // final BlinkAction blinkAction = new BlinkAction();
  // blinker.scheduleAtFixedRate(new TimerTask(){
  // public void run() {
  // blinkAction.actionPerformed(null);
  // }
  // }, 0, BLINK_DELAY);
  initListeners();
}
 
源代码17 项目: osp   文件: DataToolTab.java
/**
 * Sets the font level.
 *
 * @param level the level
 */
protected void setFontLevel(int level) {
  FontSizer.setFonts(this, level);
  plot.setFontLevel(level);
  
  FontSizer.setFonts(statsTable, level);
  FontSizer.setFonts(propsTable, level);
  
  curveFitter.setFontLevel(level);
  
  double factor = FontSizer.getFactor(level);
  plot.getAxes().resizeFonts(factor, plot);
  FontSizer.setFonts(plot.getPopupMenu(), level);
  if(propsTable.styleDialog!=null) {
    FontSizer.setFonts(propsTable.styleDialog, level);
    propsTable.styleDialog.pack();
  }
  if(dataBuilder!=null) {
    dataBuilder.setFontLevel(level);
  }
  fitterAction.actionPerformed(null);
  propsTable.refreshTable();
  
  // set shift field and label fonts in case they are not currently displayed
  FontSizer.setFonts(shiftXLabel, level);
  FontSizer.setFonts(shiftYLabel, level);
  FontSizer.setFonts(selectedXLabel, level);
  FontSizer.setFonts(selectedYLabel, level);
  FontSizer.setFonts(shiftXField, level);
  FontSizer.setFonts(shiftYField, level);
  FontSizer.setFonts(selectedXField, level);
  FontSizer.setFonts(selectedYField, level);
  shiftXField.refreshPreferredWidth();
  shiftYField.refreshPreferredWidth();
  selectedXField.refreshPreferredWidth();
  selectedYField.refreshPreferredWidth();
  toolbar.revalidate();

refreshStatusBar(null);
// kludge to display tables correctly: do propsAndStatsAction now and again after a millisecond!
  propsAndStatsAction.actionPerformed(null);
  Timer timer = new Timer(1, new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      propsAndStatsAction.actionPerformed(null);
    }
  });
timer.setRepeats(false);
timer.start();
}
 
源代码18 项目: dragonwell8_jdk   文件: WrongPaperPrintingTest.java
private static void createAndShowTestDialog() {
    String description =
        " To run this test it is required to have a virtual PDF\r\n" +
        " printer or any other printer supporting A5 paper size.\r\n" +
        "\r\n" +
        " 1. Verify that NOT A5 paper size is set as default for the\r\n" +
        " printer to be used.\r\n" +
        " 2. Click on \"Start Test\" button.\r\n" +
        " 3. In the shown print dialog select the printer and click\r\n" +
        " on \"Print\" button.\r\n" +
        " 4. Verify that a page with a drawn rectangle is printed on\r\n" +
        " a paper of A5 size which is (5.8 x 8.3 in) or\r\n" +
        " (148 x 210 mm).\r\n" +
        "\r\n" +
        " If the printed page size is correct, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("WrongPaperPrintingTest");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int)(System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("Size of a printed page is wrong.");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}
 
源代码19 项目: ramus   文件: DocBookScriptReportEditorView.java
public DocBookScriptReportEditorView(final GUIFramework framework,
                                     final Element element) {
    super(framework, element);
    timer = new Timer(500, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean save;
            synchronized (lock) {
                if (System.currentTimeMillis() - changeTime < 500)
                    return;
                save = changed;
            }

            if (save) {
                save();
                synchronized (lock) {
                    changed = false;
                }
            }
        }
    });

    timer.start();

    editorView = new ScriptEditorView(framework) {
        /**
         *
         */
        private static final long serialVersionUID = -8884124882782860341L;

        @Override
        protected void changed() {
            synchronized (lock) {
                changed = true;
                changeTime = System.currentTimeMillis();
            }
        }
    };

    editorView.load(framework.getEngine(), element);

    saved = editorView.getText();

    fullRefresh = new com.ramussoft.gui.common.event.ActionListener() {

        @Override
        public void onAction(
                com.ramussoft.gui.common.event.ActionEvent event) {
            editorView.load(framework.getEngine(), element);
        }
    };
    framework.addActionListener(Commands.FULL_REFRESH, fullRefresh);

}
 
源代码20 项目: ET_Redux   文件: AbstractDataMonitorView.java
private void initView() {
    setOpaque(true);
    setBackground(Color.white);
    try {

        this.add(redux_Icon_label);

        rawDataFilePathTextFactory();

        buttonFactory();

        progressBarFactory();

        showMostRecentFractionLabelFactory();

        dataMonitorTimer = new Timer(2500, (ActionEvent e) -> {
            monitorDataFile();
        });

        dataMonitorTimer.start();

    } catch (IOException ex) {
        Logger.getLogger(LAICPMSProjectParametersManager.class.getName()).log(Level.SEVERE, null, ex);
    }
}