Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/05/2012, 09:24
Avatar de cronopiomx
cronopiomx
 
Fecha de Ingreso: mayo-2012
Ubicación: Programing Cloud
Mensajes: 282
Antigüedad: 12 años
Puntos: 28
Pregunta Imagen en jFrame junto a GridLayout!!!???

Hola, amigos, tengo este codigo que me pinta en JPanels de un JFrame 1 tablero de ajedrez (grilla) usando un GridLayout como cuadricula, el problema esta en que quiero un poco mas al lado del tablero un espacio en mi Jframe para poner las 6 fichas del ajedrez y seleccionarlas y ubicarlas en el tablero???, ahora he intentado y como que el GridLayout se ajusta al Jframe y no se como darle las dimensiones que quiero al tablero para poder ubicar las piezas al lado????

saludos
Alex

Código:
public class Board {
    private JPanel squares[][] = new JPanel[8][8];

    public Board(){}
    
    public void buildBoard(JFrame frame)
    {
        frame = new JFrame("My Chess");
        frame.setSize(500, 500);
        frame.setLayout(new GridLayout(8, 8));

        for (int i = 0; i < 8; i++) {
          for (int j = 0; j < 8; j++) {
            squares[i][j] = new JPanel();

             if ((i + j) % 2 == 0) squares[i][j].setBackground(Color.black);
              else squares[i][j].setBackground(Color.white);
            frame.add(squares[i][j]);
          }
        }

        squares[0][0].add(new JLabel(new ImageIcon("src\\images\\wRook.gif")));
        squares[0][1].add(new JLabel(new ImageIcon("src\\images\\wKnight.gif")));
        squares[0][2].add(new JLabel(new ImageIcon("src\\images\\wBishop.gif")));
        squares[0][3].add(new JLabel(new ImageIcon("src\\images\\wQueen.gif")));
        squares[0][4].add(new JLabel(new ImageIcon("src\\images\\wKing.gif")));
        squares[0][5].add(new JLabel(new ImageIcon("src\\images\\wBishop.gif")));
        squares[0][6].add(new JLabel(new ImageIcon("src\\images\\wKnight.gif")));
        squares[0][7].add(new JLabel(new ImageIcon("src\\images\\wRook.gif")));

        squares[7][0].add(new JLabel(new ImageIcon("src\\images\\bRook.gif")));
        squares[7][1].add(new JLabel(new ImageIcon("src\\images\\bKnight.gif")));
        squares[7][2].add(new JLabel(new ImageIcon("src\\images\\bBishop.gif")));
        squares[7][3].add(new JLabel(new ImageIcon("src\\images\\bQueen.gif")));
        squares[7][4].add(new JLabel(new ImageIcon("src\\images\\bKing.gif")));
        squares[7][5].add(new JLabel(new ImageIcon("src\\images\\bBishop.gif")));
        squares[7][6].add(new JLabel(new ImageIcon("src\\images\\bKnight.gif")));
        squares[7][7].add(new JLabel(new ImageIcon("src\\images\\bRook.gif")));

        for (int i = 0; i < 8; i++) {
          squares[1][i].add(new JLabel(new ImageIcon("src\\images\\wPawn.gif")));
          squares[6][i].add(new JLabel(new ImageIcon("src\\images\\bPawn.gif")));
        }
        
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null); //center screen
        frame.setVisible(true);
    }
}