Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

49
LINES

< > BotCompany Repo | #1000877 // installTimer (AWT timer)

JavaX fragment (include)

1  
import javax.swing.event.AncestorListener;
2  
import javax.swing.event.AncestorEvent;
3  
import javax.swing.Timer;
4  
5  
// first delay = delay
6  
static Timer installTimer(JComponent component, O r, long delay) {
7  
  ret installTimer(component, r, delay, delay);
8  
}
9  
10  
// first delay = delay
11  
static Timer installTimer(RootPaneContainer frame, long delay, O r) {
12  
  ret installTimer(frame.getRootPane(), r, delay, delay);
13  
}
14  
15  
// first delay = delay
16  
static Timer installTimer(JComponent component, long delay, O r) {
17  
  ret installTimer(component, r, delay, delay);
18  
}
19  
20  
static Timer installTimer(JComponent component, long delay, long firstDelay, O r) {
21  
  ret installTimer(component, r, delay, firstDelay);
22  
}
23  
24  
static Timer installTimer(final JComponent component, final O r, final long delay, final long firstDelay) {
25  
  ret installTimer(component, r, delay, firstDelay, true);
26  
}
27  
28  
static Timer installTimer(final JComponent component, final O r, final long delay, final long firstDelay, final bool repeats) {
29  
  if (component == null) null;
30  
  ret (Timer) swingAndWait(func {
31  
    final new Var<Timer> timer;
32  
    timer.set(new Timer(toInt(delay), actionListener {
33  
      temp tempActivity(r);
34  
      pcall {
35  
        if (!allPaused())
36  
          if (isFalse(callF(r)))
37  
            cancelTimer(timer!);
38  
      }
39  
    }));
40  
    timer->setInitialDelay(toInt(firstDelay));
41  
    timer->setRepeats(repeats);
42  
    bindTimerToComponent(timer!, component);
43  
    ret timer!;
44  
  });
45  
}
46  
47  
static Timer installTimer(RootPaneContainer frame, long delay, long firstDelay, O r) {
48  
  ret installTimer(frame.getRootPane(), delay, firstDelay, r);
49  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000877
Snippet name: installTimer (AWT timer)
Eternal ID of this version: #1000877/8
Text MD5: 3e05e5ae560371225c36a9a72d13998a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-07 14:57:25
Source code size: 1637 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 804 / 1392
Version history: 7 change(s)
Referenced in: [show references]