Este applet es un ejemplo basico de como se crea la matriz de reglas.
Al presionar el boton "Agregar Elemento" se inseta una fila y columna que indica
la relacion que existe entre este elemento y los demas del grupo.
public class generareglas extends Applet{
Button nuevo;
int [][]reglas;
int MaxNumElementos;
int Nelementos;
public void init(){
nuevo=new Button("agregar elemento>");
add(nuevo);
MaxNumElementos=12;
Nelementos=1;
creaRegla();
}
public void update(Graphics g){
imprimeRegla(g);
}
public void paint(Graphics g){
repaint();
}
public boolean action(Event e, Object o) {
if (e.target == nuevo){agregaRegla(); repaint();}
return true;
}
public void creaRegla(){
reglas=new int[MaxNumElementos][MaxNumElementos];
for(int i=0;i<Nelementos;i++)
for(int j=0;j<Nelementos;j++)
reglas[i][j]=j+1;
}
public void agregaRegla(){
if(MaxNumElementos>Nelementos+1){
for(int j=0; j<Nelementos+1;j++)
reglas[Nelementos][j]=j+1;
Nelementos++;}
}
public void imprimeRegla(Graphics g){
int i,j,x,y;
Integer Val;
if(Nelementos>0){
for(i=0,y=50;i<Nelementos;i++,y+=8)
for(j=0,x=10;j<Nelementos;j++,x+=17){
Val=new Integer(reglas[i][j]);
g.drawString(Val.toString(),x,y);}}
}
int random(double num){
int i; double aux;
if(num==0) return 0;
for(i=10; i<1000000; i+=10)if(num-i<=0){aux=(Math.random()*i) % num;
return (int)aux;}
return 0;
}
int random(int num){
int i; double aux;
if(num==0) return 0;
for(i=10; i<1000000; i+=10)if(num-i<=0){aux=(Math.random()*i) % num;
return (int)aux;}
return 0;
}
}