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

ya me funciona, segui probando, ahora la duda mia es en el JPanel de la derecha voy a poner las 6 fichas del ajedrez (6 pictures), como las puedo mover de alli hacia el tablero(el otro JPanel) y que cuando suelte el click izquierdo sobre cualquiera casilla se quede en el tablero..
s2
alex
package Controls;
import javax.swing.*;
import java.awt.*;
import java.util.Locale;

/**
*
* @author Alex
*/
public class Board {
private JPanel squares[][] = new JPanel[8][8];
private JPanel board = new JPanel();
private JPanel pieces = new JPanel();

public Board(){}

public void buildBoard(JFrame frame)
{
frame = new JFrame("My Chess");
frame.setSize(550, 500);
frame.setResizable(false);
// frame.setLayout(new GridLayout(8,8));
board.setLayout(new GridLayout(8,8,4,4));

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);
board.add(squares[i][j]);
}
}
pieces.setBackground(Color.gray);
pieces.setPreferredSize(new Dimension(110,0));
frame.add(pieces, BorderLayout.EAST);
frame.add(board, BorderLayout.WEST);

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_CLOS E);
frame.setLocationRelativeTo(null); //center screen
frame.setVisible(true);
}
}