java - Add image in a GridLayout of Labels with resizing -
i new java , want make simple game of chess perhaps later add sockets. first wanted start designing board use gridlayout
jlabel
shown . problem want add each label image simulate " chip " of game not know how, tried many things not leave me, want please.
this code generated table of 8x8
public class ventana extends javax.swing.jframe { private static final int columnas = 8; private static final int filas = 8; public ventana() { initcomponents(); imageicon fnegra = new imageicon("images/fichanegra.png"); imageicon froja = new imageicon("images/ficharoja.png"); jpanel1.setlayout(new gridlayout(filas, columnas)); jlabel [][] jlabel = new jlabel[filas][columnas]; (int i=0;i<filas;i++) (int j=0;j<columnas;j++) { jlabel[i][j] = new jlabel(); jlabel[i][j].setopaque(true); if((i+j)%2 == 0) { jlabel[i][j].setbackground(color.white); jpanel1.add(jlabel[i][j]); } else { jlabel[i][j].setbackground(color.gray); jpanel1.add(jlabel[i][j]); } } this.add(jpanel1); this.setvisible(true); }
Comments
Post a Comment