K, well, I'm kind of screwed right now, I am supposed to make a game by using java, and this is all like minor stuff.
The code so far, and I have little idea of what I'm doing. I want to make it so that when you click in a certain point on the board, the chip will fall into that place with the mousePressed, but for some reason, when I open the GUIWindow, the piece is already on the board without any clicking.
Colorpanel
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ColorPanel1 extends JPanel{
int x;
int y;
private ImageIcon image, image2, image3;
public ColorPanel1(Color backColor, ImageIcon i, ImageIcon z, ImageIcon k){
setBackground(backColor);
image = i;
image2 = z;
image3 = k;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
image.paintIcon(this, g, 0, 0);
if (x <= 78 && x >= 0 && y <=78 && y >= 0)
image2.paintIcon(this, g, 0, 0);
}
public void mousePressed(MouseEvent e){
x = e.getX();
y = e.getY();
}
}
GUIWindow
import javax.swing.*;
import java.awt.*;
public class GUIWindow{
public static void main(String[] args){
JFrame theGUI = new JFrame();
theGUI.setTitle("Connect 4");
theGUI.setSize(545, 490);
theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon image = new ImageIcon("checkerboard.gif");
ImageIcon image2 = new ImageIcon("red.gif");
ImageIcon image3 = new ImageIcon("black.gif");
ColorPanel1 panel = new ColorPanel1(Color.black, image, image2, image3);
Container pane = theGUI.getContentPane();
pane.add(panel);
theGUI.setVisible(true);
}
}