Ver Mensaje Individual
  #5 (permalink)  
Antiguo 13/08/2015, 10:44
Avatar de Hobby72
Hobby72
 
Fecha de Ingreso: junio-2009
Mensajes: 34
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Crear botones con un array en Java

Hola P.Falken gracias por intervenir pero he probado de todas las forma inclusive de esta que has propuesto tu. pero no puedo ejecutar pq me da error de sintaxis o algo. dejo parte del codigo para ver si os podeis hacer una idea

public class VentanaJuegoAhorcado extends JFrame implements ActionListener{


/**
*
*/
private static final long serialVersionUID = 1L;
char[] palabraCaracteres;
char[] palabraCaracteresComprobar;
String palabra;
String palabraVirtual;
int numeroIntentos;




// creamos los componentes que necesitamos
// fila 1
JPanel fila1 = new JPanel();
JLabel titulo = new JLabel("JUEGO DEL AHORCADO", JLabel.CENTER);


// fila 2
JPanel fila2 = new JPanel();
JButton botonJugar = new JButton("Jugar");
JButton botonParar = new JButton("Parar");
JButton botonSalir = new JButton("Salir");

// fila 3

JPanel fila3 = new JPanel();
JLabel etiquetaPalabraDescubrir = new JLabel("Palabra a descubrir: ", JLabel.RIGHT);
JTextField palabraOculta = new JTextField();
JLabel etiquetaNumeroDeIntentos = new JLabel("Numero de intentos: ", JLabel.RIGHT);
JTextField numeroDeIntentos = new JTextField();



// fina 4.1
JPanel fila4 = new JPanel();

/*
JLabel etiquetaIntroduceLetra = new JLabel("Introduce una letra: ", JLabel.RIGHT);
JTextField introduceLetra = new JTextField();
JLabel etiquetaLetrasIntroducidas = new JLabel("Letras introducidas: ", JLabel.RIGHT);
JTextField letrasIntroducidas = new JTextField(JLabel.RIGHT);
*/
// fila 4.2 creacion de botones para las letras

/////////////////////////////////AQUI ESTA EL CODIGO QUE ME DISTE////////////////////////

char [] botones ={'A','B','C','D','E','F','G','H','I','J','K','L', 'M','N','O','P','Q','R','S','T','U','V','W','X','Y ','Z'};

JButton[] boton = new JButton[botones.length];

for(int i=0; i<botones.length; i++){
boton[i] = new JButton(botones[i]);
}
////////////////////////////////AQUI ESTA EL CODIGO QUE ME DISTE////////////////////////
DESGRACIADAMEMTE NO ME FUNCIONA. Me sale el aspa roja de eclipse en la linea de JButton y otra mas pequena al final de la } del ciclo for



////////////////////////// Y AQUI ESTA EL CODIGO QUE QUIERO HACER CON POCAS LINEAS////////////////////////////////////////
/*JButton botonA = new JButton("A");
JButton botonB = new JButton("B");
JButton botonC = new JButton("C");
JButton botonD = new JButton("D");
JButton botonE = new JButton("E");
JButton botonF = new JButton("F");
JButton botonG = new JButton("G");
JButton botonH = new JButton("H");
JButton botonI = new JButton("I");
JButton botonJ = new JButton("J");
JButton botonK = new JButton("K");
JButton botonL = new JButton("L");
JButton botonM = new JButton("M");
JButton botonN = new JButton("N");
JButton botonO = new JButton("O");
JButton botonP = new JButton("P");
JButton botonQ = new JButton("Q");
JButton botonR = new JButton("R");
JButton botonS = new JButton("S");
JButton botonT = new JButton("T");
JButton botonU = new JButton("U");
JButton botonV = new JButton("V");
JButton botonW = new JButton("W");
JButton botonX = new JButton("X");
JButton botonY = new JButton("Y");
JButton botonZ = new JButton("Z");*/

////////////////////////// Y AQUI ESTA EL CODIGO QUE QUIERO HACER CON POCAS LINEAS////////////////////////////////////////
LO TENGO COMENTADO PARA PROBAR



//Creacion de un JPanel y de una Label en la fila 5 para la imagen del estado del ahorcado
private final JPanel fila5 = new JPanel();
private final JLabel lblNewLabel = new JLabel("");