acá dejo el código que tengo..
este es mi JPanel "Celda"
Código Javascript
:
Ver originalpackage thegameoflife;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Celda extends javax.swing.JPanel implements ActionListener {
public Celda() {
initComponents();
this.setOpaque(false);
}
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent arg0) {
acá no se que iría.. .
}
y este es el JPanel "Matriz" que implementa Celda
Código Javascript
:
Ver originalpackage thegameoflife;
import java.util.ArrayList;
import javax.swing.ImageIcon;
public class Matriz extends javax.swing.JFrame {
int rows;
int columns;
int nrOfCells;
ArrayList<Celda> cells = new ArrayList<Celda>();
public Matriz(String size) {
initComponents();
rows = Integer.parseInt(size);
columns = Integer.parseInt(size);
System.out.println(rows+" "+columns);
mainPanel.setLayout(new java.awt.GridLayout(rows,columns,2,2));
nrOfCells = rows*columns;
for(int i=0; i<nrOfCells;i++){
cells.add(new Celda());
mainPanel.add(cells.get(cells.size()-1));
}
Imagen panel = new Imagen(new ImageIcon("images/UnderTheSea.jpg").getImage());
this.getContentPane().add(panel);
this.pack();
mainPanel.setOpaque(false);
menuPanel.setOpaque(false);
}
@SuppressWarnings("unchecked")
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Matriz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Matriz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Matriz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Matriz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
Main.matriz = new Matriz(args[0]);
Main.matriz.setVisible(true);
}
// Variables declaration - do not modify
private javax.swing.JButton AddPlankton;
private javax.swing.JButton AddSardines;
private javax.swing.JButton AddSeaUrchins;
private javax.swing.JButton AddSharks;
private javax.swing.JButton Start;
private javax.swing.JButton Stop;
private javax.swing.JPanel mainPanel;
private javax.swing.JPanel menuPanel;