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 7840121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:39:56+00:00 2026-06-02T15:39:56+00:00

I am only getting the false condition to print to the applet. I am

  • 0

I am only getting the false condition to print to the applet. I am assuming that there is something wrong with my nested if statements?

ClickableBox.Java

public class ClickableBox extends MouseAdapter {

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

  public ClickableBox(int x, int y, int width, int height, Color borderColor,
      Color backColor, boolean drawBorder, TheGame 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;
      setX(!isX);
      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 boolean isDrawBorder() {
    return drawBorder;
  }

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

  public boolean isX() {
    return isX;
  }

  public void setX(boolean isX) {
    this.isX = isX;
  }

}

TicTacToeBox.Java

 public class TicTacToeBox extends ClickableBox {

  Container parent;
  TheGame game;

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

    this.parent = parent;

  }

  public void draw(Graphics g) {

    if (isClicked()) {
      if (super.isX()) {
        g.drawLine(getX(), getY(), getX() + getWidth(), getY() + getHeight());
        g.drawLine(getX() + getWidth(), getY(), getX(), getY() + getHeight());
        if (isDrawBorder()) {
          g.drawRect(getX(), getY(), getWidth(), getHeight());
        }
      } else {
        g.drawOval(getX() + 3, getY() + 3, getWidth() - 6, getHeight() - 6);
        if (isDrawBorder()) {
          g.drawRect(getX(), getY(), getWidth(), getHeight());
        }
      }
    } else {
      g.drawRect(getX(), getY(), getWidth(), getHeight());
    }
  }

}

Here is the actual applet code as well… TheGame.java

public class TheGame extends Applet {

  private final int START_X = 20;
  private final int START_Y = 40;
  private final int ROWS = 3;
  private final int COLS = 3;
  private final int BOX_WIDTH = 70;
  private final int BOX_HEIGHT = 70;

  private TicTacToeBox boxes[][];

  private Button resetButton;
  private boolean isX;

  private boolean blank;

  public void init() {
    boxes = new TicTacToeBox[ROWS][COLS];

    resize(300, 300);
    buildBoxes();

    resetButton = new Button("Reset Game");
    resetButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {

        buildBoxes();
        repaint();
      }
    });
    add(resetButton);
  }

  public void paint(Graphics g) {
    // loop through the boxes rows

    setX(!isX);
    // System.out.println(isX());

    for (int row = 0; row < boxes.length; row++) {
      for (int col = 0; col < boxes[row].length; col++) {

        boxes[row][col].draw(g);

        if (boxes[row][col].isClicked()) {

        }
      }
    }

  }

  private void buildBoxes() {

    for (int row = 0; row < boxes.length; row++) {
      for (int col = 0; col < boxes[row].length; col++) {
        boxes[row][col] = new TicTacToeBox(START_X + col * BOX_WIDTH, START_Y
            + row * BOX_HEIGHT, BOX_WIDTH, BOX_HEIGHT, Color.black,
            Color.white, true, this);
        addMouseListener(boxes[row][col]);

      }
    }
  }

  public boolean isX() {
    return isX;
  }

  public void setX(boolean isX) {
    this.isX = isX;
  }

  public boolean isBlank() {
    return blank;
  }

  public void setBlank(boolean blank) {
    this.blank = blank;
  }

}

Any input as to how I can get the conditions to alternate from true to false and actually output what I have for each condition would be greatly appreciated.

  • 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-02T15:39:58+00:00Added an answer on June 2, 2026 at 3:39 pm

    You reinstantiate constantly TheGame, this is why you get always the same branch of your if. game should be a member of you enclosing class not a local variable and you should initalize it in your constructor:

    public class TicTacToeBox {
        private TheGame game;
    
        // I am guessing your constructor is something like this (but it is just guessing)
        public TicTacToeBox(int i, int j , int k , int l, Color c1, Color c2, boolean b, TheGame game) {
             ...
             this.game = game;
        }
        ...
        public void draw(Graphics g) {
            // TheGame game = new TheGame();
            ...
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting ready to release a tool that is only effective with regular hard
Im getting this linker error that won't let me compile. It only happens on
The false alarms are getting in the way of testing. I only have one,
I'm trying to use JOIN but it seems I am only getting half of
This is for SS 2005. Why I am i only getting 4000 characters and
I'm new to Unit Testing, and I'm only getting into the routine of building
Is the only way of getting the address of an address in C (opposite
I'm getting odd behavior (it generates only missing values) from the following loop -
I'm getting awful lot of spam to my forums where only registered users can
I keep getting this error all over the place where I only have jquery

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.