Create a NetBeans project to write Java programs to play a Tic-Tac-Toe game as follows:
If instructions below are not clear, do exactly like the demo.
NetBeans project name: p2FirstnameLastnameinitial
Use "default" package only: i.e., Your program should not have "package on the top of the program.
The project should run by pressing the "RUN (green triangle)" button of NetBeans.
Create a Java window as follows:
- Window size: 500 X 500 pixels
- Window title: p2 Firstname Lastname (e.g., p2 Hong Sung)
- A JTextField on the top of the window
Initially, "Play Tic-Tac-Toe: O's turn!" is displayed.
As the game progresses, the proper progress messages are displayed:
Who should play (O or X). 'O' plays first. Then, who is on the next turn.
Game over: Winner or Draw (tie)
Nine (9) JButtons in the 3 X 3 grid to represent the Tic-Tac-Toe game board.
Initially all labels are blank
o or X is displayed as label as the game progresses.
Once the button is played, it is disabled so that the user cannot choose already- played buttons. You are free to choose any names but meaningful ones for Java classes, variables and methods. However, those names must be in compliance with the Java naming convention.
Note: One of common logic errors students may make: Detection of the winner at the 9th move at the moment the board is full; if no winner at this moment, the game is a draw.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import javax.swing.*; // for JFrame, JLabel, JTextField
import java.awt.*; // for FlowLayout
import java.awt.event.*; // for ActionListener, ActionEvent
import static javax.swing.JFrame.EXIT_ON_CLOSE;

public class p2ClintT extends JFrame {

    private static final int WIDTH = 500;//window width
    private static final int HEIGHT = 500;//window height
    private static final int N = 3;//enter size ofthe grid
    JButton buttons[][] = new JButton[N][N];//buttons
    private JLabel lblInfo; // info
    private static final String X = "X";
    private static final String O = "O";
    private String currentPlayer = O;
    private static final Color colorX = Color.RED;
    private static final Color colorO = Color.BLUE;
    private Color currentColor = colorO;
    private int availableCells = N * N;

    public p2ClintT() {
       setTitle("p2 Clint Turnipseed");//set title of the frame
       setSize(WIDTH, HEIGHT);//set size of the frame
       setLocationRelativeTo(null);//set locaion to center

       //forces to quit the program when you press 'x' button on the right top corner
       //now create other components and add them to the frame
       //display frame and other componenets
    } // end constructor
    // Create components and add them to window.

    private void createContents() {
       //get the window content part
       Container contentPane = getContentPane();
       //set color of the background
       //create label for informing status
       lblInfo = new JLabel("Play Tic Tac Toe: " + currentPlayer + "'s turn !");
       Font font = new Font("Courier New", 1, 20);
       contentPane.add(lblInfo, BorderLayout.NORTH);
       JPanel panel = new JPanel();
       panel.setLayout(new GridLayout(N, N));
       contentPane.add(panel, BorderLayout.CENTER);

       //create buttons
       //start a loop
       for (int i = 0; i < N; i++) {
            for (int k = 0; k < N; k++) {
                //create a button
                JButton button = new JButton...

By purchasing this solution you'll be able to access the following files:

50% discount

$8.00 $4.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats