jpanel una imagen de fondo y no un color, miren el constructor de la clase, ayudaaa por favor,:
Código:
import java.awt.*; import java.awt.event.*; import javax.swing.*; final class Square extends JPanel { final private int x, y; final private BoardView bv; final private JLabel jl; private boolean mouseIn = false; private Image imgFondo; Square(int y, int x, BoardView b) { super(); this.x = x; this.y = y; bv = b; if (((x + y) % 2) == 0){ //setBackground(Color.WHITE); AQUI PONER UNA IMAGEN EN VEZ DE BACKGOUND COLOR imgFondo = new ImageIcon(getClass().getResource("/imagenes/cuaderno.png")).getImage(); } else{ //setBackground(Color.gray); AQUI PONER UNA IMAGEN EN VEZ DE BACKGOUND COLOR imgFondo = new ImageIcon(getClass().getResource("/imagenes/cuaderno.png")).getImage(); } setPreferredSize(new Dimension(42, 42)); jl = new JLabel(); jl.setPreferredSize(new Dimension(32, 32)); add(jl); addMouseListener(new SquareMouseListener()); } void setIcon(Icon i) { jl.setIcon(i); } public void paint(Graphics g) { super.paint(g); if (mouseIn) { g.setColor(Color.blue); g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); } } protected void paintComponent(Graphics g) { g.drawImage(imgFondo,0,0,null); } class SquareMouseListener extends MouseAdapter { public void mouseEntered(MouseEvent e) { mouseIn = true; repaint(); } public void mouseExited(MouseEvent e) { mouseIn = false; repaint(); } public void mouseClicked(MouseEvent e) { bv.selected(y, x); } } }