I'll see you doing a java program that consists of the typical 4 in a row of a lifetime.
The issue is that I have no idea how to do so that when I press one of the buttons I put in a column, I painted another color to simulate that the card has been inserted, does anyone know the idea of how to do it?
the current code is this:
interface
public class Interfaz {
public static void main(String[] args) {
// TODO Auto-generated method stub
Marco miMarco = new Marco();
miMarco.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Marco
class Marco extends JFrame{
public Marco() {
setVisible(true);
setTitle("4 en Raya");
setSize(700, 620);
setResizable(false);
setLocationRelativeTo(null);
Tablero miTablero = new Tablero();
add(miTablero);
miTablero.updateUI();
}
}
Board
class Tablero extends JPanel{
private Image tablero;
public Tablero() {
try {
tablero = ImageIO.read(new File("resources/mosaico.png"));
}catch(IOException e) {
e.printStackTrace();
}
setLayout(new GridLayout(1, 7));
JButton boton1 = new JButton();
JButton boton2 = new JButton();
JButton boton3 = new JButton();
JButton boton4 = new JButton();
JButton boton5 = new JButton();
JButton boton6 = new JButton();
JButton boton7 = new JButton();
add(boton1);
boton1.setContentAreaFilled(false);
add(boton2);
boton2.setContentAreaFilled(false);
add(boton3);
boton3.setContentAreaFilled(false);
add(boton4);
boton4.setContentAreaFilled(false);
add(boton5);
boton5.setContentAreaFilled(false);
add(boton6);
boton6.setContentAreaFilled(false);
add(boton7);
boton7.setContentAreaFilled(false);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(tablero, 0, 0, this);
}
}