Puoi fare cosi: ti definisci una tua classe MyThread che estende Thread che definisce il comportamento del tuo thread (ciò lo si fa ridefinendo il metodo run() di un thread). Quindi nel metodo spegni istanzi un nuovo MyThread, passandogli nel costruttore il valore a:
Codice PHP:
public void spegni() {
int a = Integer.valueOf(tempo.getText()).intValue();
Thread t = new MyThread(a);
t.start();
}
class MyThread extends Thread{
private int a;
public MyThread(int a){
this.a = a;
t.setName("Nuovo thread creato con valore 'a' pari a: " + a);
t.setPriority(10);
}
public void run(){
System.out.println("Thread in esecuzione: " + this);
try {
for (int n = a; n > 0; n--) {
System.out.println("" + n);
sleep(1000);
}
catch (InterruptedException e) {
System.out.println("Thread interrotto");
}
}
}