类javax.swing.Timer源码实例Demo

下面列出了怎么用javax.swing.Timer的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: open-ig   文件: MapRenderer.java
/** Preset. */
public MapRenderer() {
	setOpaque(true);
	addMouseListener(ma);
	addMouseMotionListener(ma);
	addMouseListener(sma);
	addMouseMotionListener(sma);
	animationTimer = new Timer(100, new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			//wrap animation index
			if (animation == Integer.MAX_VALUE) {
				animation = -1;
			}
			animation++;
			if (surface != null && surface.buildings.size() > 0) {
				boolean blink0 = blink;
				blink = (animation % 10) >= 5;
				if (blink0 != blink || (animation % 3 == 0)) {
					repaint();
				}
			}
		}
	});
	animationTimer.start();
}
 
源代码2 项目: rapidminer-studio   文件: RepaintFilter.java
RepaintFilter(final ProcessRendererView view) {
	ActionListener repaintListener = new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent e) {
			counter++;

			if (repaintRequested.get() && counter >= COUNTER_BARRIER) {
				counter = 0;
				repaintRequested.set(false);
				view.doRepaint();
			}
		}

	};

	Timer timer = new Timer(TIMER_INTERVAL, repaintListener);
	timer.start();
}
 
源代码3 项目: 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();
}
 
TestWindow(final int num) {
    super("Test Window [" + num + "]");
    setMinimumSize(new Dimension(300, 200));
    setLocation(100 + 400 * (num - 1), 100);

    setLayout(new BorderLayout());
    JLabel textBlock = new JLabel("Lorem ipsum dolor sit amet...");
    add(textBlock);

    btn = new JButton("TEST");
    add(btn, BorderLayout.SOUTH);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();

    t = new Timer(INTERVAL, this);
    t.setRepeats(false);
}
 
源代码5 项目: pumpernickel   文件: AnimatedLayout.java
@Override
public void layoutContainer(Container parent) {
	JComponent jc = (JComponent) parent;
	install(jc);
	Timer timer = (Timer) jc.getClientProperty(PROPERTY_TIMER);
	Boolean layoutImmediately = (Boolean) jc
			.getClientProperty(PROPERTY_LAYOUT_IMMEDIATELY);
	if (layoutImmediately == null)
		layoutImmediately = false;
	if (layoutImmediately) {
		layoutContainerImmediately(jc);
		if (parent.isShowing())
			jc.putClientProperty(PROPERTY_LAYOUT_IMMEDIATELY, false);
	} else {
		if (!timer.isRunning())
			timer.start();
	}
}
 
源代码6 项目: netbeans   文件: BranchSelector.java
public BranchSelector (File repository) {
    this.repository = repository;
    panel = new BranchSelectorPanel();
    panel.branchList.setCellRenderer(new RevisionRenderer());
    
    filterTimer = new Timer(300, new ActionListener() {
        @Override
        public void actionPerformed (ActionEvent e) {
            filterTimer.stop();
            applyFilter();
        }
    });
    panel.txtFilter.getDocument().addDocumentListener(this);
    panel.branchList.addListSelectionListener(this);
    panel.jPanel1.setVisible(false);
    cancelButton = new JButton();
    org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(BranchSelector.class, "CTL_BranchSelector_Action_Cancel")); // NOI18N
    cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BranchSelector.class, "ACSD_BranchSelector_Action_Cancel")); // NOI18N
    cancelButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(BranchSelector.class, "ACSN_BranchSelector_Action_Cancel")); // NOI18N
}
 
源代码7 项目: ghidra   文件: CursorBlinker.java
public CursorBlinker(FieldPanel panel) {
	this.fieldPanel = panel;

	timer = new Timer(500, new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			if (paintBounds != null) {
				showCursor = !showCursor;
				fieldPanel.paintImmediately(paintBounds);
			}
			else {
				timer.stop();
			}
		}
	});

	// the initial painting is laggy for some reason, so shorten the delay
	timer.setInitialDelay(100);
	timer.start();

}
 
源代码8 项目: RipplePower   文件: RPToast.java
public void fadeOut() {
	final Timer timer = new Timer(FADE_REFRESH_RATE, null);
	timer.setRepeats(true);
	timer.addActionListener(new ActionListener() {
		private float opacity = MAX_OPACITY;

		@Override
		public void actionPerformed(ActionEvent e) {
			opacity -= OPACITY_INCREMENT;
			setOpacity(Math.max(opacity, 0));
			if (opacity <= 0) {
				timer.stop();
				setVisible(false);
				dispose();
			}
		}
	});
	setOpacity(MAX_OPACITY);
	timer.start();
}
 
源代码9 项目: mts   文件: RTStatsTimer.java
public RTStatsTimer(){

        // We call the constructer of the parent-class
        super();

        // We get the configuration of GUI_REFRESH_INTERVAL
        double interval = Config.getConfigByName("tester.properties").getDouble("stats.GUI_REFRESH_INTERVAL", 1);

        // We create a new timer with this config value as interval
        clock = new Timer((int)(interval * 1000), this);

        // We want an action repeating
        clock.setRepeats(true);

        // We start the timer
        clock.start();

        // We record this in the logger
        GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.CORE, "Refresh interval for real-times statistics is ", interval, "s");
    }
 
源代码10 项目: jclic   文件: TextGrid.java
/** Creates new TextGridBox */
public TextGrid(AbstractBox parent, JComponent container, double setX, double setY, int setNcw, int setNch,
    double setCellW, double setCellH, BoxBase boxBase, boolean setBorder) {
  super(parent, container, boxBase);
  x = setX;
  y = setY;
  nCols = Math.max(1, setNcw);
  nRows = Math.max(1, setNch);
  cellWidth = Math.max(setCellW, MIN_CELL_SIZE);
  cellHeight = Math.max(setCellH, MIN_CELL_SIZE);
  width = cellWidth * nCols;
  height = cellHeight * nRows;
  chars = new char[nRows][nCols];
  attributes = new int[nRows][nCols];
  preferredBounds.setRect(getBounds());
  setBorder(setBorder);
  cursorTimer = new Timer(500, this);
  cursorTimer.setRepeats(true);
  cursorEnabled = false;
  useCursor = false;
  wildTransparent = false;
  answers = null;
}
 
源代码11 项目: Quelea   文件: MainToolbar.java
public void startRecording() {
        recordAudioButton.setSelected(true);
        recording = true;
//        getItems().add(pb);
        getItems().add(recordingPathTextField);
        recordAudioButton.setText("Recording...");
        recordAudioButton.setSelected(true);
        recordingsHandler = new RecordButtonHandler();
        recordingsHandler.passVariables("rec", pb, recordingPathTextField, recordAudioButton);
        final int interval = 1000; // 1000 ms
        recCount = new Timer(interval, (java.awt.event.ActionEvent e) -> {
            recTime += interval;
            setTime(recTime, recordAudioButton);
        });
        recCount.start();
    }
 
源代码12 项目: netbeans   文件: TextEditorSupport.java
/**
 * Initialize timers and handle their ticks.
 */
private void initTimer() {
    timer = new Timer(0, new java.awt.event.ActionListener() {
        // we are called from the AWT thread so put itno other one
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("$$ TextEditorSupport::initTimer::actionPerformed: event = " + e);

            RequestProcessor.postRequest( new Runnable() {
                public void run() {
                    syncDocument(false);
                }
            });
        }
    });

    timer.setInitialDelay(getAutoParsingDelay());
    timer.setRepeats(false);
}
 
TestWindow(final int num) {
    super("Test Window [" + num + "]");
    setMinimumSize(new Dimension(300, 200));
    setLocation(100 + 400 * (num - 1), 100);

    setLayout(new BorderLayout());
    JLabel textBlock = new JLabel("Lorem ipsum dolor sit amet...");
    add(textBlock);

    btn = new JButton("TEST");
    add(btn, BorderLayout.SOUTH);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();

    t = new Timer(INTERVAL, this);
    t.setRepeats(false);
}
 
源代码14 项目: netbeans   文件: MemoryView.java
/**
 * Initializes the Form
 */
public MemoryView() {
    initComponents();

    setTitle(bundle.getString("TXT_TITLE"));
    doGarbage.setText(bundle.getString("TXT_GARBAGE"));
    doRefresh.setText(bundle.getString("TXT_REFRESH"));
    doClose.setText(bundle.getString("TXT_CLOSE"));

    txtTime.setText(bundle.getString("TXT_TIME"));
    doTime.setText(bundle.getString("TXT_SET_TIME"));
    time.setText(String.valueOf(UPDATE_TIME));
    time.selectAll();
    time.requestFocus();

    updateStatus();

    timer = new Timer(UPDATE_TIME, new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            updateStatus();
        }
    });
    timer.setRepeats(true);

    pack();
}
 
源代码15 项目: WorldPainter   文件: ThreeDeeView.java
@Override
    public void hierarchyChanged(HierarchyEvent event) {
        if ((event.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
            if (isDisplayable()) {
//                for (Tile tile: dimension.getTiles()) {
//                    threeDeeRenderManager.renderTile(tile);
//                }
                timer = new Timer(250, this);
                timer.start();
            } else {
                timer.stop();
                timer = null;
                threeDeeRenderManager.stop();
                for (Tile tile : dimension.getTiles()) {
                    tile.removeListener(this);
                }
                dimension.removeDimensionListener(this);
            }
        }
    }
 
源代码16 项目: netbeans   文件: ProfilerWindow.java
private void updateSettings(boolean valid) {
    start.setEnabled(valid);
    
    boolean _configure = features.getActivated().isEmpty();
    start.setVisible(!_configure);
    stop.setVisible(!_configure);
    configure.setVisible(_configure);
    
    new Timer(0, null) {
        {
            setRepeats(false);
            setInitialDelay(50);
        }
        protected void fireActionPerformed(ActionEvent e) {
            updateFocus();
        }
    }.start();
    
    if (session.inProgress()) session.doModify(features.getSettings());
}
 
源代码17 项目: JCommunique   文件: SlideManager.java
public void animate(Notification note, Location loc, double delay, double slideDelta, boolean slideIn) {
	m_note = note;
	m_x = note.getX();
	m_y = note.getY();
	m_delta = Math.abs(slideDelta);
	m_slideIn = slideIn;
	m_startLocation = loc;
	if (m_slideIn) {
		m_stopX = m_standardScreen.getX(m_startLocation, note);
		m_stopY = m_standardScreen.getY(m_startLocation, note);
	} else {
		m_stopX = m_noPaddingScreen.getX(m_startLocation, note);
		m_stopY = m_noPaddingScreen.getY(m_startLocation, note);
	}

	Timer timer = new Timer((int) delay, this);
	timer.start();
}
 
源代码18 项目: netbeans   文件: DragWindow.java
private Timer createInitialEffect() {
    final Timer timer = new Timer(100, null);
    timer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if( contentAlpha < 1.0f ) {
                contentAlpha += ALPHA_INCREMENT;
            } else {
                timer.stop();
            }
            if( contentAlpha > 1.0f )
                contentAlpha = 1.0f;
            repaintImageBuffer();
            repaint();
        }
    });
    timer.setInitialDelay(0);
    return timer;
}
 
源代码19 项目: netbeans   文件: DragWindow.java
private Timer createNoDropEffect() {
    final Timer timer = new Timer(100, null);
    timer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if( contentAlpha > NO_DROP_ALPHA ) {
                contentAlpha -= ALPHA_INCREMENT;
            } else {
                timer.stop();
            }
            if( contentAlpha < NO_DROP_ALPHA )
                contentAlpha = NO_DROP_ALPHA;
            repaintImageBuffer();
            repaint();
        }
    });
    timer.setInitialDelay(0);
    return timer;
}
 
源代码20 项目: RemoteSupportTool   文件: StaffApplication.java
@Override
public void start() {
    monitoringTimer = new Timer(1000, e -> {
        if (uploadMonitor == null || downloadMonitor == null)
            return;
        try {
            frame.setRates(downloadMonitor.getAverageRate(), uploadMonitor.getAverageRate());

            Date minAge = new Date(System.currentTimeMillis() - 2000);
            downloadMonitor.removeOldSamples(minAge);
            uploadMonitor.removeOldSamples(minAge);
        } catch (Exception ex) {
            LOGGER.warn("Can't upload monitoring!", ex);
        }
    });
    monitoringTimer.setRepeats(true);
    monitoringTimer.start();

    super.start();
}
 
源代码21 项目: 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);
}
 
源代码22 项目: 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;
    }
}
 
源代码23 项目: dragonwell8_jdk   文件: AquaScrollBarUI.java
protected void installListeners() {
    fTrackListener = createTrackListener();
    fModelListener = createModelListener();
    fPropertyChangeListener = createPropertyChangeListener();
    fScrollBar.addMouseListener(fTrackListener);
    fScrollBar.addMouseMotionListener(fTrackListener);
    fScrollBar.getModel().addChangeListener(fModelListener);
    fScrollBar.addPropertyChangeListener(fPropertyChangeListener);
    fScrollListener = createScrollListener();
    fScrollTimer = new Timer(kNormalDelay, fScrollListener);
    fScrollTimer.setInitialDelay(kInitialDelay); // default InitialDelay?
}
 
源代码24 项目: dragonwell8_jdk   文件: AquaScrollBarUI.java
public void actionPerformed(final ActionEvent e) {
    if (fUseBlockIncrement) {
        Hit newPart = getPartHit(fTrackListener.fCurrentMouseX, fTrackListener.fCurrentMouseY);

        if (newPart == ScrollBarHit.TRACK_MIN || newPart == ScrollBarHit.TRACK_MAX) {
            final int newDirection = (newPart == ScrollBarHit.TRACK_MAX ? 1 : -1);
            if (fDirection != newDirection) {
                fDirection = newDirection;
            }
        }

        scrollByBlock(fDirection);
        newPart = getPartHit(fTrackListener.fCurrentMouseX, fTrackListener.fCurrentMouseY);

        if (newPart == ScrollBarHit.THUMB) {
            ((Timer)e.getSource()).stop();
        }
    } else {
        scrollByUnit(fDirection);
    }

    if (fDirection > 0 && fScrollBar.getValue() + fScrollBar.getVisibleAmount() >= fScrollBar.getMaximum()) {
        ((Timer)e.getSource()).stop();
    } else if (fDirection < 0 && fScrollBar.getValue() <= fScrollBar.getMinimum()) {
        ((Timer)e.getSource()).stop();
    }
}
 
源代码25 项目: Swing9patch   文件: Toast.java
public Toast(int delay, String message, Point p)
	{
//		super(parent);
		initGUI();
		
		// init datas
		timer = new Timer(delay, this);
		toastPane.setMessage(message);
		this.showPossition = p;
	}
 
源代码26 项目: mars-sim   文件: Clock.java
public Clock() {
      super();
      CLOCK_TIMER = new Timer(1000, this);
      INNER_BOUNDS = new Rectangle(200, 200);
      init(getInnerBounds().width, getInnerBounds().height);
      setPointerColor(ColorDef.BLACK);
      horizontalAlignment = SwingConstants.CENTER;
verticalAlignment = SwingConstants.CENTER;
      //CLOCK_TIMER.start();
  }
 
源代码27 项目: binnavi   文件: JStackPanel.java
@Override
public void actionPerformed(final ActionEvent event) {
  if (m_model.hasData(m_startAddress, m_numberOfBytes)) {
    JStackPanel.this.setEnabled(true);
    setDefinitionStatus(DefinitionStatus.DEFINED);

    ((Timer) event.getSource()).stop();
  } else if (!m_model.keepTrying()) {
    ((Timer) event.getSource()).stop();
  }
}
 
源代码28 项目: 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;
}
 
源代码29 项目: azure-devops-intellij   文件: ImportForm.java
private void createUIComponents() {
    userAccountPanel = new UserAccountPanel();
    refreshButton = new JButton(AllIcons.Actions.Refresh);

    // Create timer for filtering the list
    timer = new Timer(400, null);
    timer.setInitialDelay(400);
    timer.setActionCommand(CMD_PROJECT_FILTER_CHANGED);
    timer.setRepeats(false);
}
 
源代码30 项目: 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);
}
 
 类所在包
 同包方法