me dejaron un proyecto de hacer un juego llamado batalla naval un ejemplo lo pueden ver en
esta direccion... [Enlace externo eliminado para invitados]
el problema es que quiero hacerlo igual igual como ese ejemplo....
mi duda es la siguiente, hice una matriz de botones que me llena un jframe padre con botones de igual tama;o , el problema es que yo quiero hacer un jframe padre que contenga dos jframe hijos y que cada jframe hijo contenga la matriz de botones.... programo desde NetBeans IDE 7.1.2 y los frame los agrego desde la interfaz grafica de NetBeans.
el codigo que me llena el jframe padre es este...
Código: Seleccionar todo
public class Menu2 extends javax.swing.JFrame {
/**
* Creates new form Menu2
*/
public Menu2() {
initComponents();
}
private JButton[][] boton;
private int n;
/**
* Creates a new instance of Main
*/
@SuppressWarnings("OverridableMethodCallInConstructor")
public Menu2(int n) {
this.n = n;
boton = new JButton[n][n];
this.setLayout(new GridLayout(n, n));
this.setBounds(6, 6, 4, 4);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
boton[i][j] = new JButton();
String nombre = new Integer(i).toString();
nombre += new Integer(j).toString();
boton[i][j].setActionCommand(nombre);
this.add(boton[i][j]);
}
}
this.accionBotones();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(new Dimension(800, 600));
}
public void accionBotones() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
boton[i][j].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JButton accion = (JButton) evt.getSource();
System.out.println("apretado el boton " + accion.getActionCommand());
/* if (Integer.parseInt(accion.getActionCommand()) == 2) {
boton[0][2].setIcon(new ImageIcon(getClass().getResource("Explosion.gif")));
Timer timer = new Timer(2000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
boton[0][2].setIcon(new ImageIcon(getClass().getResource("fuego.gif")));
boton[6][8].setIcon(new ImageIcon(getClass().getResource("fuego.gif")));
}
});
timer.start();
}
*
*/
}
});
}
}
}