I've been making a tic tac toe game for school that takes user input through the console and then displays the current board state in GUI. I have all of the code to make sure the game runs as it is supposed to, however I can't figure out how to draw the X or O images onto the board as the players play. It draws the board fine when the constructor is called, but it doesn't change at all when I call my methods to draw the images. I don't know a whole lot about GUI and absolutely any help is appreciated.
My code:
package part1;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class boardDraw extends JFrame{
private ImageIcon XIcon = new ImageIcon("XJava.png");
private ImageIcon OIcon = new ImageIcon("OJava.png");
private Image X = XIcon.getImage();
private Image O = OIcon.getImage();
private Point[][] coords = new Point[3][3];
public boardDraw(){
setTitle("Tic-Tac-Toe");
setSize(1000, 1000);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
fillCoords();
}
public void paint(Graphics g){
g.drawLine(0, 333, 1000, 333);
g.drawLine(0, 666, 1000, 666);
g.drawLine(333, 0, 333, 1000);
g.drawLine(666, 0, 666, 1000);
}
public void fillCoords(){
int x = 170;
int y = 170;
for(int i = 0; i<3; i++){
for(int j = 0; j<3; j++){
coords[i][j] = new Point(x, y);
y += 333;
}
x += 333;
}
}
public void setX(int row, int col){
Graphics g = this.getGraphics();
//g.drawImage(X, (int)coords[row][col].getX(), (int)coords[row][col].getY(), null);
//System.out.println(X);
}
public void setO(int row, int col){
Graphics g = this.getGraphics();
g.drawImage(O, (int)coords[row][col].getX(), (int)coords[row][col].getY(), this);
//System.out.println(O);
//g.drawOval((int)coords[row][col].getX(), (int)coords[row][col].getY(), 100, 100);
}
}