Botones en JAVA

Jimcesse
19 de Diciembre del 2007
Buenas,

Tengo la tarea de desarrollar un juego en JAVA, que consta de lo siguiente:

Llenar una matriz de 5 x 5 con numeros aleatorios luego, dada una posicion de la matriz por ejemplo (matriz[0][1] y matriz[3][1]) comparar si estos valores son iguiales que en algun lado muestre !!!! GANO !!!.

Ya la parte de llenar la matriz y motrar los botones en el Applet esta lista.

La pregunta es como le asigno a cada uno de esos 25 botones el valor de cada uno de los 25 subindices de la matriz y que cuando el usuario precione el boton 5 por ejemplo el valla hasta el sub indice de la matriz [0][5] y muestre ese valor.

Les paso una copia del codigo, como lo tengo hasta el momento, de antemano muchas gracias por la ayuda.

Saludos, Jimcesse.

import java.awt.*;
import java.applet.*;
import javax.swing.*;

public class Memoria extends Applet
{
int memoria [][] = new int [5][5];
int capture;
private Button boton1;
private Button boton2;
private Button boton3;
private Button boton4;
private Button boton5;
private Button boton6;
private Button boton7;
private Button boton8;
private Button boton9;
private Button boton10;
private Button boton11;
private Button boton12;
private Button boton13;
private Button boton14;
private Button boton15;
private Button boton16;
private Button boton17;
private Button boton18;
private Button boton19;
private Button boton20;
private Button boton21;
private Button boton22;
private Button boton23;
private Button boton24;
private Button boton25;
private Button boton26;
private Button boton27;
private Button boton28;
private Label texto1;
// private TextField entrada1;
Font f = new Font("Times New Roman", Font.BOLD,17);
Image imagen;



public void init()
{
Dimension WH = Toolkit.getDefaultToolkit().getScreenSize();
resize ((WH.width),(WH.height));
setLayout(null);
// setBackground(java.awt.Color.BLACK);
// imagen=getImage(Memoria,"Instrucciones");

}

public void paint(Graphics g)
{

LlenarMatriz (memoria,g,50);
// ImprimeMatriz(memoria,g,100);
GUI();
// action((capture=memoria[0][0]),boton1);
// g.drawImage(imagen,20,400,this);

}


public void LlenarMatriz (int a [][],Graphics g,int num)
{
int azar = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
azar = (int) (Math.random() * num);
a [i][j] = azar;

}
}

}

public void ImprimeMatriz (int a [][],Graphics g,int posicion)
{
int poscol=50;
g.setFont(f);
g.setColor(Color.red);
g.drawString("La Solución del Juego Es :", 60, 60 );
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
g.drawString(" "+a[i][j],poscol,posicion);
poscol+=50;
}
poscol=50;
posicion+=30;
}
}

public void GUI ()
{

boton1 = new Button (" * 1 *");
boton2 = new Button (" * 2 *");
boton3 = new Button (" * 3 *");
boton4 = new Button (" * 4 *");
boton5 = new Button (" * 5 *");
boton6 = new Button (" * 6 *");
boton7 = new Button (" * 7 *");
boton8 = new Button (" * 8 *");
boton9 = new Button (" * 9 *");
boton10 = new Button (" * 10 *");
boton11 = new Button (" * 11 *");
boton12 = new Button (" * 12 *");
boton13 = new Button (" * 13 *");
boton14 = new Button (" * 14 *");
boton15 = new Button (" * 15 *");
boton16 = new Button (" * 16 *");
boton17 = new Button (" * 17 *");
boton18 = new Button (" * 18 *");
boton19 = new Button (" * 19 *");
boton20 = new Button (" * 20 *");
boton21 = new Button (" * 21 *");
boton22 = new Button (" * 22 *");
boton23 = new Button (" * 23 *");
boton24 = new Button (" * 24 *");
boton25 = new Button (" * 25 *");
boton26 = new Button (" Mostrar Solución ");
boton27 = new Button (" Iniciar ");
boton28 = new Button (" Salir ");
texto1 = new Label ("Valor Uno : "+capture);
// entrada1 = new TextField ();

add(boton1);
add(boton2);
add(boton3);
add(boton4);
add(boton5);
add(boton6);
add(boton7);
add(boton8);
add(boton9);
add(boton10);
add(boton11);
add(boton12);
add(boton13);
add(boton14);
add(boton15);
add(boton16);
add(boton17);
add(boton18);
add(boton19);
add(boton20);
add(boton21);
add(boton22);
add(boton23);
add(boton24);
add(boton25);
add(boton26);
add(boton27);
add(boton28);
add(texto1);
//add(entrada1);

boton1.reshape (50,300,40,30);
boton2.reshape (100,300,40,30);
boton3.reshape (150,300,40,30);
boton4.reshape (200,300,40,30);
boton5.reshape (250,300,40,30);
boton6.reshape (50,350,40,30);
boton7.reshape (100,350,40,30);
boton8.reshape (150,350,40,30);
boton9.reshape (200,350,40,30);
boton10.reshape (250,350,40,30);
boton11.reshape (50,400,40,30);
boton12.reshape (100,400,40,30);
boton13.reshape (150,400,40,30);
boton14.reshape (200,400,40,30);
boton15.reshape (250,400,40,30);
boton16.reshape (50,450,40,30);
boton17.reshape (100,450,40,30);
boton18.reshape (150,450,40,30);
boton19.reshape (200,450,40,30);
boton20.reshape (250,450,40,30);
boton21.reshape (50,500,40,30);
boton22.reshape (100,500,40,30);
boton23.reshape (150,500,40,30);
boton24.reshape (200,500,40,30);
boton25.reshape (250,500,40,30);
boton26.reshape (350,300,120,30);
boton27.reshape (350,400,120,30);
boton28.reshape (350,500,120,30);
texto1.reshape (50,600,120,30);
//entrada1.reshape (80,600,120,30);
}
/*
public boolean action (Event e, Object o)
{
if (e.target instanceof Button)
{
if (e.target==boton26)
{
capture = memoria[0][0];
repaint();

numdep=Integer.parseInt(entrada1.getText());
sala=Float.parseFloat(entrada2.getText());
repaint();
entrada1.setText("");entrada2.setText("");


}
}
return true;
}
*/
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == boton26)
ImprimeMatriz(memoria,g,100);
}

}