import java.awt.*; import java.awt.geom.*; import javax.swing.*; /** * Write a description of class TicTacToeBoardComponent here. * * @author (your name) * @version (a version number or a date) */ public class TicTacToeBoardComponent extends JComponent { /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public void paintComponent(Graphics g) { int boardSize = 300; int boardTopY = 100; int boardLeftX =100; int spaceAmount = 5; //recover Graphics 2D Graphics2D g2 = (Graphics2D) g; // Draw the vertical lines int xPos = boardLeftX + boardSize/3; Line2D.Double vertical1 = new Line2D.Double(xPos, boardTopY, xPos, boardTopY+boardSize); xPos = boardLeftX + 2*boardSize/3; Line2D.Double vertical2 = new Line2D.Double(xPos, boardTopY, xPos, boardTopY+boardSize); // Draw the horizontal lines int yPos = boardTopY + boardSize/3; Line2D.Double horizontal1 = new Line2D.Double(boardLeftX, yPos, boardLeftX+boardSize, yPos); yPos = boardTopY + 2*boardSize/3; Line2D.Double horizontal2 = new Line2D.Double(boardLeftX, yPos, boardLeftX+boardSize, yPos); // Draw the lines g2.setColor(Color.BLACK); g2.draw(vertical1); g2.draw(vertical2); g2.draw(horizontal1); g2.draw(horizontal2); // draw an X in the upper left corner int xPos2 = boardLeftX + boardSize/3 - spaceAmount; int yPos2 = boardTopY + boardSize/3 - spaceAmount; g2.draw(new Line2D.Double(boardLeftX + spaceAmount, boardTopY + spaceAmount, xPos2, yPos2)); xPos = xPos2; yPos = boardTopY + spaceAmount; xPos2 = boardLeftX + spaceAmount; g2.draw(new Line2D.Double(xPos, yPos, xPos2, yPos2)); // draw an O to its right int diameter = boardSize/3 - 2* spaceAmount; Ellipse2D.Double circle = new Ellipse2D.Double(boardTopY + boardSize/3 + spaceAmount, boardLeftX + spaceAmount, diameter, diameter); g2.draw(circle); } }