Create a 2-player Tic Tac Toe. Match the given style and implied functionality as closely as possible. X wins. After each click, check to see if the game has ended. If X or O wins, show the appropriate message. If there's a tie, show the appropriate message. After the game ends, reset the board. The first click on a empty cell should put X on the button. The next click on an empty cell should put O on the button. Follow this pattern for the rest of the game. If the user clicks on a button that already has an X or O, do nothing. Replace the button label text with pictures instead.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Create a 2-player Tic Tac Toe. Match the given style and implied functionality as closely as possible.
X wins.
  • After each click, check to see if the game has ended. If X or O wins, show the appropriate message. If there's a tie, show the appropriate message.
  • After the game ends, reset the board.
  • The first click on a empty cell should put X on the button. The next click on an empty cell should put O on the button. Follow this pattern for the rest of the game.
  • If the user clicks on a button that already has an X or O, do nothing.
  • Replace the button label text with pictures instead.

This is my code:


super.setTitle("Tic Tac Toe");
super.setSize(300, 300);
super.setDefaultCloseOperation(EXIT_ON_CLOSE);
buildPanel();
super.setVisible(true);
}

public void buildPanel()
{

GridLayout g = new GridLayout(3, 3);
super.setLayout(g);

for(int i=0; i<board.length;i++)
{
board[i]=new JButton();
board[i].addActionListener(this);
super.add(board[i]);
}
}
public void actionPerformed(ActionEvent ae)
{
JButton player = (JButton)ae.getSource();

//Checking Which Players turn it is
if(turn)
{

if(!player.getText().equals(""))
return;


player.setText("X");


boxFilled++;

if(checkWinner("X"))
{
JOptionPane.showMessageDialog(this,"X wins!\nResetting...");
resetBoard();
return;
}

}
else
{
if(!player.getText().equals(""))
return;

player.setText("O");

boxFilled++;

if(checkWinner("O"))
{
JOptionPane.showMessageDialog(this,"O wins!\nResetting...");
resetBoard();
return;
}

}

if(boxFilled==9)
{
JOptionPane.showMessageDialog(this,"Cat's game\nResetting...");
resetBoard();
return;
}

turn=!turn;
}
public boolean checkWinner(String player)
{

if(board[0].getText().equals(player) && board[1].getText().equals(player) && board[2].getText().equals(player))
{
return true;
}
if(board[3].getText().equals(player) && board[4].getText().equals(player) && board[5].getText().equals(player))
{
return true;
}
if(board[6].getText().equals(player) && board[7].getText().equals(player) && board[8].getText().equals(player))
{
return true;
}
if(board[0].getText().equals(player) && board[3].getText().equals(player) && board[6].getText().equals(player))
{
return true;
}
if(board[4].getText().equals(player) && board[1].getText().equals(player) && board[7].getText().equals(player))
{
return true;
}
if(board[8].getText().equals(player) && board[5].getText().equals(player) && board[2].getText().equals(player))
{
return true;
}
if(board[0].getText().equals(player) && board[4].getText().equals(player) && board[8].getText().equals(player))
{
return true;
}
if(board[2].getText().equals(player) && board[4].getText().equals(player) && board[6].getText().equals(player))
{
return true;
}
return false;
}
public void resetBoard()
{
turn=true;
boxFilled=0;
for(JButton btn: board)
{
btn.setText("");
}
}

public static void main(String[] args)
{
new TicTacToe();
}
}

However i need to replace the button label text with pictures instead

I beleive i am supposed to use some sort of combobox coding/ contol to provide the pictures 

can someone help me with this coding to implement a .png file 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Web Page
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education