下面列出了javax.swing.Timer#stop ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void createTimer() {
final Icon[] busyIcons = new Icon[15];
for (int i = 0; i < busyIcons.length; i++) busyIcons[i] = new ImageIcon(getClass().getResource("/org/graalvm/visualvm/core/ui/resources/busy-icon" + i + ".png")); // NOI18N
busyIconTimer = new Timer(ANIMATION_RATE, new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!ANIMATE) {
if (busyIconTimer != null) busyIconTimer.stop(); // Stop animation
presenter1.setIcon(new ImageIcon(getClass().getResource("/org/graalvm/visualvm/core/ui/resources/busy-icon4.png"))); // NOI18N
} else {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
if (!DataSourceCaption.this.isShowing()) return;
presenter1.setIcon(busyIcons[busyIconIndex]);
}
}
});
}
public void actionPerformed(ActionEvent evt) {
ActionListener src = (ActionListener)ref.get();
if (src != null) {
src.actionPerformed(evt);
} else { // source listener was garbage collected
if (evt.getSource() instanceof Timer) {
Timer timer = (Timer)evt.getSource();
timer.removeActionListener(this);
if (stopTimer) {
timer.stop();
}
}
}
}
/** Creates new form SearchHistoryPanel */
public SearchHistoryPanel(File repository, RepositoryInfo info, File [] roots, SearchCriteriaPanel criteria) {
this.roots = roots;
this.repository = repository;
this.info = info;
this.criteria = criteria;
this.diffViewFactory = new SearchHistoryTopComponent.DiffResultsViewFactory();
criteriaVisible = true;
explorerManager = new ExplorerManager ();
initComponents();
initializeFilter();
filterTimer = new Timer(500, this);
filterTimer.setRepeats(false);
filterTimer.stop();
setupComponents();
info.addPropertyChangeListener(list = WeakListeners.propertyChange(this, info));
aquaBackgroundWorkaround();
refreshComponents(true);
}
/** Creates new form SearchHistoryPanel */
public SearchHistoryPanel(File [] roots, SearchCriteriaPanel criteria) {
this.bOutSearch = false;
this.bIncomingSearch = false;
this.roots = roots;
this.criteria = criteria;
this.diffViewFactory = new SearchHistoryTopComponent.DiffResultsViewFactory();
criteriaVisible = true;
explorerManager = new ExplorerManager ();
initComponents();
initializeFilter();
filterTimer = new Timer(500, this);
filterTimer.setRepeats(false);
filterTimer.stop();
setupComponents();
aquaBackgroundWorkaround();
refreshComponents(true);
}
@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);
}
}
}
public void actionPerformed(ActionEvent e) {
Timer timer = (Timer) e.getSource();
boolean workToDo = false;
synchronized (container.getTreeLock()) {
Map<JComponent, Rectangle> destinationMap = getDestinationMap(container);
for (Entry<JComponent, Rectangle> entry : destinationMap
.entrySet()) {
if (nudge(entry.getKey(), entry.getValue()) == false) {
workToDo = true;
}
}
}
// on Windows, Ladislav pointed out there's a repaint problem
container.repaint();
if (workToDo == false)
timer.stop();
}
public ProgressMonitorWrapper(String msg, Runnable task) {
pbar = new ProgressMonitor(null, msg, "Elapsed: 0 secs", 0, 4);
start_time = System.currentTimeMillis();
timer = new Timer(500, this);
timer.start();
thread = new Thread(() -> {
task.run();
timer.stop();
pbar.close();
});
thread.start();
}
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);
}
/**
* punishes the User by moving the Chatwindow around for 10 seconds
*/
public void startRandomMovement(final int seconds)
{
if(window instanceof JFrame){
JFrame f = (JFrame)window;
f.setState(Frame.NORMAL);
f.setVisible(true);
}
SparkManager.getNativeManager().flashWindow(window);
final long startTime = System.currentTimeMillis()/1000L;
moveTimer = new Timer(5, e -> {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
double x = Math.random()*10000 % d.getWidth();
double y = Math.random()*10000 % d.getHeight();
int xx = Math.round(Math.round(x));
int yy = Math.round(Math.round(y));
window.setLocation(xx,yy);
window.repaint();
long now = System.currentTimeMillis()/1000L;
long diff = now-startTime;
System.out.println(diff);
if(diff > seconds)
{
moveTimer.stop();
}
} );
moveTimer.start();
}
public AnimatedIcon(List<? extends Icon> icons, int frameDelay, int framesToSkip) {
this.iconList = icons;
this.skipFrames = framesToSkip;
timer = new Timer(frameDelay, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (--paintCounter <= 0) {
timer.stop();
return;
}
if (skipFrameCount > 0) {
skipFrameCount--;
return;
}
if (++currentIconIndex >= iconList.size()) {
currentIconIndex = 0;
skipFrameCount = skipFrames;
}
if (component != null) {
component.repaint();
}
}
});
for (Icon icon : iconList) {
width = Math.max(width, icon.getIconWidth());
height = Math.max(height, icon.getIconHeight());
}
}
@Override
public void actionPerformed(ActionEvent evt) {
plotterCache.remove(key);
Timer t = timerCache.remove(key);
t.stop();
((XMBeanAttributes) table).collapse(attributeName, this);
}
private void setupProgress() {
setIcon(createProgressIcon());
t = new Timer(100, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Component comp = refComp.get();
TreeListNode nd = refNode.get();
if (nd == null && comp == null) {
t.stop();
Container p = getParent();
if (p != null) {
p.remove(ProgressLabel.this);
}
} else {
busyIcon.tick();
ProgressLabel.this.repaint();
if (nd != null) {
nd.fireContentChanged();
} else {
comp.repaint();
}
}
}
});
t.setRepeats(true);
super.setVisible(false);
}
/**
* Default constructor
*/
public KLHandlerGeneric()
{
// set the logger object
log = Logger.getLogger("com.fr3ts0n.prot.kl");
commTimer = new Timer(commTimeoutTime, commTimeoutHandler);
commTimer.setInitialDelay(commTimeoutTime);
commTimer.stop();
}
private Registration timerReg(final Timer timer) {
return new Registration() {
@Override
protected void doRemove() {
if (timer.isRunning()) {
timer.stop();
}
}
};
}
/**
* construct with connecting to device
*
* @param device device to connect
*/
private KLHandlerGeneric(String device)
{
try
{
setDeviceName(device);
} catch (Exception ex)
{
log.log(Level.SEVERE,"", ex);
}
commTimer = new Timer(commTimeoutTime, commTimeoutHandler);
commTimer.setInitialDelay(commTimeoutTime);
commTimer.stop();
}
private PatchNameListener (ShelveChangesPanel panel, JButton okButton, Dialog dialog) {
this.panel = panel;
this.button = okButton;
this.dialog = dialog;
timer = new Timer(300, this);
timer.stop();
}
public CardDecksPanel() {
decksJList.setOpaque(false);
decksJList.setBackground(new Color(0, 0, 0, 1));
decksJList.setForeground(Color.BLACK);
decksJList.setFocusable(true);
decksJList.setCellRenderer(new CardDecksListCellRenderer());
decksJList.setFont(FontsAndBorders.FONT1);
// scroll pane for deck names list
scroller.setViewportView(decksJList);
scroller.setBorder(null);
scroller.setOpaque(false);
scroller.getViewport().setOpaque(false);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
decksJList.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent evt) {
if (isDoubleClick(evt)) {
showSelectedDeck(decksJList.locationToIndex(evt.getPoint()));
}
}
});
miglayout.setLayoutConstraints("insets 0, flowy");
setLayout(miglayout);
// these constraints fix decksButton in CardPanel not resizing correctly
// when full screen and decksbutton is clicked to re-show image. Ensure you
// test if these constraints are updated especially if you add an 'h' constraint.
add(scroller, "w 100%, growy, pushy");
cooldownTimer = new Timer(TIMER_DELAY_MSECS, e -> {
cooldownTimer.stop();
showDecksContainingCard(CardDecksPanel.this.card);
});
}
TagManager (File repository) {
this.repository = repository;
this.panel = new TagManagerPanel();
panel.tagList.setCellRenderer(new TagRenderer());
filterTimer = new Timer(300, new ActionListener() {
@Override
public void actionPerformed (ActionEvent e) {
filterTimer.stop();
applyFilter();
}
});
attachListeners();
}
private void initGUI() {
renderer = new ReflectionRenderer();
setBackgroundPainter(new MattePainter(PaintUtils.NIGHT_GRAY, true));
GestionnaireEvenements interactionManager = new GestionnaireEvenements(this);
this.addMouseListener(interactionManager);
this.addMouseMotionListener(interactionManager);
this.addMouseWheelListener(interactionManager);
timer = new Timer(30, e -> {
repaint();
xScale += xDelta;
if (xScale > 1 || xScale < -1) {
xDelta *= -1;
}
if (loop > 0 && ((int) xScale == 1 || (int) xScale == -1)) {
timer.stop();
launched = false;
}
loop++;
});
}
/**
* 显示窗体
*/
public void showFrame()
{
this.setAlwaysOnTop(true);
if(chat==null)
btn打开.setVisible(false);
int width=350;
int height=266;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(screenSize.width-width-3,screenSize.height,width,height);
setVisible(true);
Timer timer=new Timer(10, new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
setLocation(getLocation().x, getLocation().y-10);
}
});
timer.start();
while(true)
{
// 25表示任务栏的高度,好奇怪,有的电脑注释掉下面的输出语句就会出现弹窗不停止的奇怪现象
System.out.println("当前高度:"+getLocation().y+",屏幕高度:"+screenSize.height);
if(getLocation().y+height<screenSize.height-25)
{
timer.stop();
break;
}
}
}