I'm doing a small application that makes a draw among several participants and shows the result in a JDialog. I have two errors in the code that do not allow it to execute well:
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
// Convierte el arreglo textoConNombres a una lista listaNombres
String[] textoConNombres = jTextArea1.getText().split("\n");
List<String> listaNombres = new ArrayList<>
(Arrays.asList(textoConNombres));
Random sorteo = new Random();
// Obtiene el valor del comboBox
//No puedo castear de object a int en la parte de JComboBox1
int cantTitulares = Integer.parseInt(jComboBox1.getSelectedItem());
ArrayList ganadorTitular = new ArrayList();
/* Hace el sorteo las veces que dice el comboBox
agrega al ganador a un arrayList aparte
lo elimina de la lista para hacer el sorteo con el resto
de los participantes que quedan sin ganar.*/
for (int i = 0; i < cantTitulares; i++) {
int ganador = sorteo.nextInt(listaNombres.size());
ganadorTitular.add(ganador);
listaNombres.remove(ganador);
}
// Muestra el resultado en VentanaGanador, que es otra clase
VentanaGanador ventGanador = new VentanaGanador();
for (int i = 0; i < ganadorTitular.size(); i++) {
// Aquí no puedo seleccionar el índice del array para mostrar el elemento
ventGanador.etiquetaGanador.setText(/////);
}
The idea is basically that within the for
the random will be made and the person who won will be removed so that they do not get drawn again. The problem is that I can not show the Array objects, I tried and searched but I do not know how.