Usa una JComboBox threadList per tenere la lista dei thread creati; nel frame principale puoi quindi aggiungere:
Codice PHP:
JComboBox threadList = new JCombobox();
threadList.objects.addActionListener(this);
threadList.setEditable(false);
Nel metodo actionPerfomed, quando è creato un nuovo thread, aggiungi alla lista il thread:
Codice PHP:
threadList.addItem(thread);
threadList.setSelectedItem(thread);
Per visualizzare i nomi dei thread, nella tua classe MioThread implementa un metodo
pubic String toString()
che ritorna il nome del thread.
Quando gestisci la pressione di un pulsante che ad esempio deve interrompere un tread, ti ricavi dalla JComboBox il thread correntemente selezionato ed esegui l'azione, esempio:
[PHP]
if(source == interruptButton){
Object o = threadList.getSelectedItem();
if(o == null)
return;
Thread selectedThread = (Thread)o;
selectedThread.interrupt();
}
[PHP]