Question: The fist image is what my code is showing when running. The second image is what it should look like when running.What is wrong with
The fist image is what my code is showing when running. The second image is what it should look like when running.What is wrong with my code
package games.boards;
import javax.swing.JPanel;
import java.awt.;
@SuppressWarningsserial
public class Board extends JPanel
private Cell cells;
public Boardint rows, int columns, ActionListener ah
cells new Cellrowscolumns;
this.setLayoutnew GridLayout;
for int r ; r cells.length; r
for int c ; c cellsrlength; c
cellsrc new Cellrc;
this.addcellsrc;
cellsrcaddActionListenerah;
private void setLayoutGridLayout gridLayout
TODO Autogenerated method stub
public void setCellMark mark, int row, int column
throws IllegalArgumentException
try
if cellsrowcolumngetContent Mark.EMPTY
cellsrowcolumnsetContentmark;
else
System.out.printlncell already occupied";
catch ArrayIndexOutOfBoundsException e
System.out.printlninvalid cell selection";
public Cell getCellint row, int column
return cellsrowcolumn;
public String toString
StringBuilder str new StringBuilder;
for int r ; r ; r
strappend;
for int c ; c ; c
switchcellsrcgetContent
case NOUGHT:
strappend;
break;
case CROSS:
strappendX;
break;
case YELLOW:
strappendY;
break;
case RED:
strappendR;
break;
case BLUE:
strappendB;
break;
case GREEN:
strappendG;
break;
case MAGENTA:
strappendM;
break;
case ORANGE:
strappendO;
break;
default: Empty
strappend ;
strappend;
strappend
;
return strtoString;
package games.boards;
import javax.swing.JButton;
import java.awt.Graphics;
import java.awt.GraphicsD;
import java.awt.BasicStroke;
import java.awt.Color;
@SuppressWarningsserial
public class Cell extends JButton
private Mark content;
private int row, column;
public Cellint row, int column
this.row row;
this.column column;
content Mark.EMPTY;
public Mark getContent return content;
public void setContentMark content
this.content content;
public int getRow return row;
public int getColumn return column;
@Override
public void paintComponentGraphics g
paint the basic button first
super.paintComponentg;
int offset ;
GraphicsD gGraphicsD g;
gsetStrokenew BasicStroke;
now paint or X if required
switchcontent
case NOUGHT:
Draw O
gsetColorColorRED;
gdrawOvaloffsetoffset,
this.getWidth offset
this.getHeight offset ;
break;
case CROSS:
Draw X
gsetColorColorBLACK;
gdrawLineoffset offset,
this.getWidth offset
this.getHeight offset ;
gdrawLinethisgetWidth offset,
offset, offset,
this.getHeight offset;
break;
default:
break;
public void addActionListenerActionListener ah
TODO Autogenerated method stub
package games.boards;
import java.awt.event.ActionEvent;
import javax.swing.;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import games.utilities.FileManager;
@SuppressWarnings "serial", "unused"
public class BoardGameTester extends JFrame
public static void mainString args
SwingUtilities.invokeLater new Runnable
public void run new BoardGameTester;
;
private Board gb;
private int turn;
private void takeTurnCell c
Mark curMark turn
Mark.NOUGHT: Mark.CROSS;
gbsetCellcurMarkcgetRowcgetColumn;
private BoardGameTester
gb new Board new ActionListener
public void actionPerformedActionEvent ae
Cell c Cell aegetSource;
takeTurnc;
;
this.addgb;
this.setDefaultCloseOperationEXITONCLOSE;
this.setTitleTICTACTOE";
this.setSize;
this.setVisibletrue;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
