He hecho esto rapido, lo cual requerirá quizás que hagas algunos ajustes:
CaballosForm.java:
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class CaballosForm {
// TODO ...
private HiloCaballo []hiloCaballos = null;
public static void main
(String[] args
) { public void run() {
try {
CaballosForm window = new CaballosForm();
window.frmCaballos.setVisible(true);
e.printStackTrace();
}
}
});
}
public CaballosForm() {
initialize();
}
private void initialize() {
frmCaballos.setTitle("Caballos");
frmCaballos.setBounds(100, 100, 450, 300);
frmCaballos.
setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE); frmCaballos.getContentPane().setLayout(null);
lblNewLabel.setDisplayedMnemonic('C');
lblNewLabel.setBounds(12, 12, 70, 15);
frmCaballos.getContentPane().add(lblNewLabel);
lblNewLabel.setLabelFor(numeroTxt);
numeroTxt.setBounds(104, 10, 114, 19);
frmCaballos.getContentPane().add(numeroTxt);
numeroTxt.setColumns(10);
int n
= Integer.
parseInt(numeroTxt.
getText()); int y_factor = 39;
hiloCaballos = new HiloCaballo[n];
for(int i = 0; i < n; i++) {
hiloCaballos[i] = new HiloCaballo();
hiloCaballos[i].start();
hiloCaballos[i].getCaballo().setBounds(12, y_factor, 256, 14);
frmCaballos.getContentPane().add(hiloCaballos[i].getCaballo());
y_factor += 15;
}
frmCaballos.revalidate();
frmCaballos.pack();
frmCaballos.setBounds(100, 100, 450, 300);
}
});
btnNewButton.setMnemonic('O');
btnNewButton.setBounds(230, 7, 117, 25);
frmCaballos.getContentPane().add(btnNewButton);
for(int i
= 0; i
< Integer.
parseInt(numeroTxt.
getText()); i
++) { hiloCaballos[i].detenerHilo();
}
}
});
btnStop.setBounds(364, 7, 70, 25);
frmCaballos.getContentPane().add(btnStop);
}
}
HiloCaballo.java:
import javax.swing.JProgressBar;
public class HiloCaballo
extends Thread {
private boolean stopFlag = false;
public HiloCaballo() {
progressCaballo.setValue(0);
}
return progressCaballo;
}
@Override
public void run() {
while(!stopFlag) {
progressCaballo.
setValue((int)(Math.
random() * 100.0)); try {
}
}
}
public void detenerHilo() {
stopFlag = true;
}
}