I'm new to coding and trying to create a simple tic-tac-toe game for class and I figured since I need to use GUI that i'd make the board a grid of buttons. Unfortunately I am having issues getting the buttons to do anything. I want to when someone clicks on it for it to become an X, and then the next person that clicks it becomes an O. Any help would be fantastic.
import javax.swing.*;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JOptionPane;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.layout.BorderPane;
import javafx.geometry.Pos;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
import java.awt.font.*;
import javafx.animation.TranslateTransition;
import javafx.scene.layout.GridPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class ShadowT extends JFrame {
//creates 9 buttons
private static JButton buttons[] = new JButton[9];
//sets counter for amount of times a button has been clicked on
public static int counter = 0;
public static String letter;
public static void main(String[] args){
//creates grid of 3x3
int rows = 3;
int cols = 3;
ShadowT grid = new ShadowT(rows,cols);
grid.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
grid.pack();
grid.setVisible(true);
}
public ShadowT(int rows, int cols){
//creates pane with grid and adds in the buttons
Container pane = getContentPane();
pane.setLayout(new GridLayout(rows,cols));
for(int i = 0; i < 9; i++){
JButton button = new JButton(Integer.toString((i+1)));
pane.add(button);
}
}
}