Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/07/2012, 16:48
Sephyneko
 
Fecha de Ingreso: junio-2012
Mensajes: 17
Antigüedad: 11 años, 10 meses
Puntos: 2
StackOverflowErro

bueno habia hecho un applet del juego 3 en raya, un ejercicio de un libro.

en applet funciona muy bien. el tema es que ahora quise pasarlo a JFrame para probar las características de este y ademas introduciendo los conceptos de varias clases (creo que a esto se le llama herencia), soy muy nuevo en esta parte de java.

el juego nuevo tiene clases por separado

-clase "Ejecutable" (el que ejecuta el "programa")
-clase "MainVentana" (acá puse la posición de los botones y la forma de la "ventana"
-clase "Botones" (acá se inicializa los botones de la "ventana" y el menú de pantalla)
-clase "evento" (bueno acá se le da acción a los botones del "programa")
-clase "juego3x3" y "juego 4x4" acá esta todo el funcionamiento del juego)

Bueno esto sale como error:

Cita:
Exception in thread "main" java.lang.StackOverflowError;
y me marca como veinte o 30 veces estas misma linea:
Cita:
at com.wawanime.JFrame3.tateti.EventosMenu.<init>(Eve ntosMenu.java:10)
at com.wawanime.JFrame3.tateti.BotonesJuego.<init>(Bo tonesJuego.java:9)
he leido por ahi que el problema este es "a bad recursive call." algo asi como una llamada "recursiva" y dice que cuando no las defino con la terminacion correcta se llaman una y otra vez por siempre.

les dejo el codigo a ver si me dan una idea por donde va el problema, a mi me parece que es algo conceptual el error. le di mil vueltas y nada.

clase "ejecutable"
Código java:
Ver original
  1. public class Ejecutable {
  2.     public static void main(String [] args){
  3.         MainVentana a=new MainVentana();
  4.         a.setDefaultCloseOperation(a.EXIT_ON_CLOSE);
  5.         a.setVisible(true);
  6.         a.setBounds(400, 300, 350, 290);
  7.     }
  8. }

clase "MainVentana"
Código java:
Ver original
  1. public class MainVentana extends JFrame{
  2.    
  3.     JTextField Estado=new JTextField();
  4.     JTextField Estado2=new JTextField();
  5.     BotonesJuego boton=new BotonesJuego();
  6.    
  7.     MainVentana(){
  8.        
  9.         //definir atributo del frame--------
  10.         setTitle("TATETI - Tres En Raya");
  11.         setLayout(null);
  12.         setResizable(false);
  13.         setBackground(Color.black);
  14.    
  15.         //Estado del juego ---jugador1----jugador2----
  16.         Estado.setEditable(false);
  17.         Estado.setBounds(10, 190, 170, 20);
  18.         Estado.setVisible(true);
  19.         add(Estado);
  20.         //juego seleccionado---3x3----4x4-----
  21.         Estado2.setEditable(false);
  22.         Estado2.setBounds(10, 220, 170, 20);
  23.         Estado2.setVisible(true);
  24.         add(Estado2);
  25.         //llamando a los metodos de botones
  26.         BJuego3x3();
  27.         BJuego4x4();
  28.         menupantalla();
  29.     }  
  30.  
  31. //agrega los botnes y les da su posicion inicial-------------------------------
  32.     public void BJuego3x3(){
  33.        
  34.         boton.BJuego3x3();
  35.         for (int i=0;i<boton.tateti3.length;i++){
  36.             for (int j=0;j<boton.tateti3[i].length;j++){
  37.                 add(boton.tateti3[i][j]);
  38.             }
  39.         }
  40.         boton.tateti3[0][0].setBounds(10, 10, 50, 50);
  41.         boton.tateti3[0][1].setBounds(70, 10, 50, 50);
  42.         boton.tateti3[0][2].setBounds(130, 10, 50, 50);
  43.         boton.tateti3[1][0].setBounds(10, 70, 50, 50);
  44.         boton.tateti3[1][1].setBounds(70, 70, 50, 50);
  45.         boton.tateti3[1][2].setBounds(130, 70, 50, 50);
  46.         boton.tateti3[2][0].setBounds(10, 130, 50, 50);
  47.         boton.tateti3[2][1].setBounds(70, 130, 50, 50);
  48.         boton.tateti3[2][2].setBounds(130, 130, 50, 50);
  49.        
  50.     }//fin de metodo BJuego3x3
  51.  
  52.     public void BJuego4x4(){
  53.         boton.BJuego4x4();
  54.         boton.tateti4[0][0].setBounds(10, 10, 30, 30);
  55.         boton.tateti4[0][1].setBounds(60, 10, 30, 30);
  56.         boton.tateti4[0][2].setBounds(110, 10, 30, 30);
  57.         boton.tateti4[0][3].setBounds(160, 10, 30, 30);
  58.         boton.tateti4[1][0].setBounds(10, 60, 30, 30);
  59.         boton.tateti4[1][1].setBounds(60, 60, 30, 30);
  60.         boton.tateti4[1][2].setBounds(110, 60, 30, 30);
  61.         boton.tateti4[1][3].setBounds(160, 60, 30, 30);
  62.         boton.tateti4[2][0].setBounds(10, 110, 30, 30);
  63.         boton.tateti4[2][1].setBounds(60, 110, 30, 30);
  64.         boton.tateti4[2][2].setBounds(110, 110, 30, 30);
  65.         boton.tateti4[2][3].setBounds(160, 110, 30, 30);
  66.         boton.tateti4[3][0].setBounds(10, 160, 30, 30);
  67.         boton.tateti4[3][1].setBounds(60, 160, 30, 30);
  68.         boton.tateti4[3][2].setBounds(110, 160, 30, 30);
  69.         boton.tateti4[3][3].setBounds(160, 160, 30, 30);
  70.        
  71.         for (int i=0;i<boton.tateti4.length;i++){
  72.             for (int j=0;j<boton.tateti4[i].length;j++){
  73.                 add(boton.tateti4[i][j]);
  74.             }
  75.         }//fin de for
  76.     }//fin de metodo
  77.    
  78.     public void menupantalla(){
  79.         int y=10;
  80.         for (int i=0;i<boton.opciones.length;){
  81.         boton.opciones[i].setBounds(200, y, 120, 30);
  82.         y+=40;
  83.         add(boton.opciones[i]);
  84.         }
  85. }
  86. }//fin de metodo


clase "BotonesJuego"
Código java:
Ver original
  1. public class BotonesJuego extends JButton{
  2.    
  3.     JButton tateti3[][]=new JButton[3][3];
  4.     JButton tateti4[][]=new JButton[4][4];
  5.     EventosMenu evt=new EventosMenu();
  6.     JButton opciones[]=new JButton[6];
  7.     String opt[]={"Un Jugador","Dos Jugadores","Tres X Tres","Cuatro X Cuatro","Nuevo Juego","Salir"};
  8.     //atributos de botones para "tres en raya" en matriz de 3x3
  9.     public void BJuego3x3(){
  10.    
  11.         for (int i=0;i<tateti3.length;i++){
  12.             for (int j=0;j<tateti3[i].length;j++){
  13.                 tateti3[i][j]=new JButton(" * ");
  14.                 tateti3[i][j].setVisible(false);
  15.                 tateti3[i][j].addActionListener(evt);
  16.                 }
  17.         }
  18.  
  19.     }
  20.     //atributos de botones para "tres en raya" en matriz de 4x4
  21.     public void BJuego4x4(){
  22.     for (int i=0;i<tateti4.length;i++){
  23.          for (int j=0;j<tateti4[i].length;j++){
  24.             tateti4[i][j]=new JButton(" * ");
  25.             tateti4[i][j].setVisible(false);
  26.             tateti4[i][j].addActionListener(evt);
  27.          }
  28.      }
  29.  
  30.     }
  31.     //atributos de menu del programa
  32.     public void menu(){
  33.         for (int i=0;i<opciones.length;i++){
  34.             opciones[i]=new JButton(opt[i]);
  35.             opciones[i].setVisible(true);
  36.             opciones[i].addActionListener(evt);
  37.         }
  38.     }
  39.     }

clase "eventos"
Código java:
Ver original
  1. public class EventosMenu implements ActionListener{
  2.  
  3.     BotonesJuego boton=new BotonesJuego();
  4. //Accion Boton juego 3x3------------------------------------------------------
  5.     public void actionPerformed(ActionEvent e) {
  6.        
  7.         if(boton.opciones[2]==e.getSource()){
  8.             //Borrar botones 4x4-------------------
  9.             for (int i=0;i<boton.tateti4.length;i++){
  10.                  for (int j=0;j<boton.tateti4[i].length;j++){
  11.                     boton.tateti4[i][j].setVisible(false);
  12.                  }
  13.              }
  14.             //iniciar botones 3x3-------------------
  15.             for (int i=0;i<boton.tateti3.length;i++){
  16.                 for (int j=0;j<boton.tateti3[i].length;j++){
  17.                     boton.tateti3[i][j].setVisible(true);
  18.                     }
  19.             }
  20.         }
  21. //Accion Boton juego 4x4------------------------------------------------------
  22.        
  23.         if (boton.opciones[3]==e.getSource()){
  24.             //Borrar botones juego 3x3------------------
  25.             for (int i=0;i<boton.tateti3.length;i++){
  26.                 for (int j=0;j<boton.tateti3[i].length;j++){
  27.                     boton.tateti3[i][j].setVisible(false);
  28.                     }
  29.             }
  30.             //iniciar botones juego 4x4------------------
  31.             for (int i=0;i<boton.tateti4.length;i++){
  32.                  for (int j=0;j<boton.tateti4[i].length;j++){
  33.                     boton.tateti4[i][j].setVisible(true);
  34.                  }
  35.              }
  36.         }
  37.    
  38.    
  39.     }//fin de Action Event
  40.  
  41. }//Fin de Clase Eventos Menu