MCPcopy Create free account
hub / github.com/HelloBush/Java_MHXYdemo / main

Method main

src/pkgTest/TestTimer.java:14–42  ·  view source on GitHub ↗
(String args[])

Source from the content-addressed store, hash-verified

12 //ÿ��Timer�������һ����̨�̣߳����ڰ�˳��ִ�����м�ʱ��������
13 static int i=0;
14 public static void main(String args[]) throws AWTException{
15 Timer myTimer = new Timer();
16 TimerTask myTimerTask1 = new TimerTask(){
17
18 public void run() {
19 System.out.println(i++);
20// if(this.i==5)
21// //��ʱ���������Ҫͨ��Timer��cancel()��ȡ������̣߳���������һֱ����
22// myTimer.cancel();
23 }
24 };
25 myTimer.schedule(myTimerTask1, 2000,1000);
26
27 Robot robot = new Robot();
28 while(i<=10){
29 robot.delay(1000);
30 if(i==5){
31 myTimer.cancel();
32 System.out.println("Timer��Robotȡ���ˣ�");
33 i++;
34 }
35 else if(i>5){
36 System.out.println("������Robot���ӹ�i++��i="+i++);
37 }
38 }
39
40
41
42 }
43}

Callers

nothing calls this directly

Calls 1

delayMethod · 0.80

Tested by

no test coverage detected