I want to change the icon used by imageicon in this code to another one by clicking in that imageicon. Can anybody help me please? what can i do in this code?? and i want it to also make fall down if the bottom is filled with white color.If one user click at the white point the color changes to yellow then after, if again click on another white one the color changes to red.
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
class Connect4Games extends JFrame implements ActionListener, MouseListener
{
JFrame frame;
JPanel pane;
JLabel insertaxis[][];
ImageIcon EmptySpace, circleYellow, circleRed ;
BufferedImage bufferedImage;
public Connect4Games() {
LookAndFeel.setLookAndFeel();
pane = new JPanel();
frame = new JFrame();
insertaxis = new JLabel[6][7];
EmptySpace = new ImageIcon("image/Circle.png");
circleYellow = new ImageIcon("image/Circle2.png");
circleRed = new ImageIcon("image/Circle3.png");
pane.setLayout(new GridLayout(6, 7));
pane.setBackground(Color.blue);
add(pane);
addMouseListener(this);
setTitle("Connect 4");
setVisible(true);
setSize(670, 590);
frame.pack();
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 7; j++) {
insertaxis[i][j] = new JLabel();
pane.add(insertaxis[i][j]);
insertaxis[i][j].setIcon(EmptySpace);
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
}
public static void main(String[] args) {
new Connect4Games();
}
@Override
public void mouseClicked(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if(e.getPoint() == null){
insertaxis[x][y].setIcon(circleRed);
}
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}