Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7706231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:04:28+00:00 2026-06-01T00:04:28+00:00

I have a CLickableBox class that creates boxes for me and now I need

  • 0

I have a CLickableBox class that creates boxes for me and now I need to make it so that when clicked, either an X or an O will be displayed in place. Here is the ClickableBox class.

 import java.awt.event.MouseAdapter;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.Container;


public class ClickableBox extends MouseAdapter {

  private int x, y, width, height;
  private Color borderColor, backColor, oldColor;
  private boolean drawBorder, clicked;
  private Container parent;

  public ClickableBox(int x, int y, int width, int height, Color borderColor, 
      Color backColor, boolean drawBorder, Container parent) {

    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    this.borderColor = borderColor;
    this.backColor = backColor;
    this.drawBorder = drawBorder;
    this.parent = parent;



  }

  public void draw(Graphics g) {

    oldColor = g.getColor();
    g.setColor(backColor);
    g.fillRect(x, y, width, height);
    if(drawBorder) {
        g.setColor(borderColor);
        g.drawRect(x, y, width, height);
    }
    g.setColor(oldColor);
  }

  public void mouseReleased(MouseEvent e) {
    if(x < e.getX() && e.getX() < x + width &&
         y < e.getY() && e.getY() < y + height) {
        clicked = true;
        parent.repaint();
    }
  }

  public boolean isClicked() {
    return clicked;
  }


  public int getX() {
    return x;
  }

  public void setX(int x) {
    this.x = x;
  }

  public int getY() {
    return y;
  }

  public void setY(int y) {
    this.y = y;
  }

  public int getWidth() {
    return width;
  }

  public void setWidth(int width) {
    this.width = width;
  }

  public int getHeight() {
    return height;
  }

  public void setHeight(int height) {
    this.height = height;
  }

  public Color getBorderColor() {
    return borderColor;
  }

  public void setBorderColor(Color borderColor) {
    this.borderColor = borderColor;
  }

  public Color getBackColor() {
    return backColor;
  }

  public void setBackColor(Color backColor) {
    this.backColor = backColor;
  }

  public Color getOldColor() {
    return oldColor;
  }

  public void setOldColor(Color oldColor) {
    this.oldColor = oldColor;
  }

  public boolean isDrawBorder() {
    return drawBorder;
  }

  public void setDrawBorder(boolean drawBorder) {
    this.drawBorder = drawBorder;
  }



  public void setClicked(boolean clicked) {
    this.clicked = clicked;
}
}

The TicTacToeBox class should extend ClickableBox, so that each box will be a listener. It needs to be designed so that each Box object will take care of itself- it knows if it’s been clicked or not, and if so, whether it’s going to be showing an x or an o.

The TicTacToeBox class is what I am having trouble with. This is what I will need for my game board. Any suggestions on how to implement this, simply? Below is my TicTacToeBox so far (not much):

Some direction and/or assistance would be greatly appreciated! Thanks.

import java.awt.Color;
import java.awt.Container;


public class TicTacToeBox extends ClickableBox {

  public TicTacToeBox(int x, int y, int width, int height, Color borderColor,
      Color backColor, boolean drawBorder, boolean mask, Container parent)
  {
    super(x, y, width, height, borderColor, backColor, drawBorder, parent);

  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:04:29+00:00Added an answer on June 1, 2026 at 12:04 am

    Perhaps you need to override mouseReleased() – something like this:

    public void mouseReleased(MouseEvent e) {
      if ( this.value == NONE ) {
        if ( currentTurn == Turn.X ) {
          this.value = X;
        }
        else {
          this.value = O;
        }
      }
      super.mouseReleased();
    }
    

    With some global currentTurn variable to keep track of whose turn it is, and a value field to represent what the current value of this box is. You’d also probably want to override draw() to make it render the “X” or “O”…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have been trying couple of hours now to make my iphone app universal. The
I have a table row that has background color on hover. When user clicks
**Have it working now. I forgot to populate the Array List. How embarrassing. I'm
Have searched the database but need to specifically sum(of hours flown or days off)in
Have a bunch of WCF REST services hosted on Azure that access a SQL
I have an NSStatusItem that has an NSMenuItem which contains a custom NSView. this
Have a look at one of my websites: moskah.com The problem is that it
Have some dates in my local Oracle 11g database that are in this format:
Have an app that can use tts to read text messages. It can also
Have such a problem, hope you'll help me.. Can't find anywhere. Here is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.