1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
package com.irnbru;
public interface IEvent {
void stuff(int i);
}
puis à faire
package com.irnbru;
public class Worker implements Runnable {
public int i;
private IEvent ie;
public Worker(IEvent ie){
this.ie = ie;
}
@Override
public void run() {
// TODO Auto-generated method stub
for(int j=0; j < 1000; j++){
i = j;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(j%10==0){
ie.stuff(j);
}
}
}
}
Enfin
public class ProgramTest implements IEvent {
public static void main(String[] args){
Worker oWorker = new Worker(new ProgramTest ());
Thread t = new Thread(oWorker);
t.start();
}
@Override
public void stuff(int i) {
System.out.println("ok " + i);
}
} |
Partager