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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:09:25+00:00 2026-06-12T07:09:25+00:00

Hello all I have this problem that I can’t seem to fix. I’ve been

  • 0

Hello all I have this problem that I can’t seem to fix. I’ve been given some code and have to make a “tic tac toe” game. Fairly primitive. At the moment what it want’s me to do is take user input (it just asks for what row / column you want to place the marker) and it is meant to draw an oval on the appropriate square of the board. My current code is as following the work has specified that I make a new class to deal with user input.

I am currently just mucking around with trying to get it to add new items to the JFrame but am having little success. I have a dummy call for input, it doesn’t check to see what I’ve typed it just calls an oval that SHOULD sit in the first square in the top left corner. I can get the object to draw onto the JFrame (albeit it takes up the whole frame) but it is always BEHIND the actual board (ie: if I stretch the frame I can see the circle). I’ve tried adding JPanels and so forth so that they sit on top of the board but so far I am having little luck.

Here is the code for creating the Oval which I was given for the task. All I am doing is instantiating a new oval with position (0,0,10,10). When it draws however it takes up the WHOLE JFrame but it is also BEHIND the actual board…… any ideas?

package lab4;

import javax.swing.*;
import java.awt.*;

/** Oval Supplier Class 
 * Author: David D. Riley
 * Date: April, 2004
 */
public class Oval extends JComponent  {

    /** post:   getX() == x  and  getY() == y
     *          and  getWidth() == w  and getHeight() == h
     *          and  getBackground() == Color.black
     */
    public Oval(int x, int y, int w, int h)  {
        super();
        setBounds(x, y, w, h);
        setBackground(Color.black);
    }

    /** post:   this method draws a filled Oval
     *          and  the upper left corner of the bounding rectangle is (getX(), getY()) 
     *          and  the oval's dimensions are getWidth() and getHeight()
     *          and  the oval's color is getBackground()
     */
    public void paint(Graphics g)  {
        g.setColor( getBackground() );
        g.fillOval(0, 0, getWidth()-1, getHeight()-1);
        paintChildren(g);
   }

}

EDIT: THIS IS NOW THE CODE WE ARE LOOKING AT–

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lab4;

/**
 *
 * @author Scott
 */
import java.awt.*;
import java.util.Scanner;
import javax.swing.*;

public class GameBoard {

    private JFrame win;
    private int count = 1;

    //Create new GUI layout
    GridLayout layout = new GridLayout(3, 3);
    JPanel panel = new JPanel(layout);

    //Create a new Array of Rectangles
    Rectangle[][] rect = new Rectangle[3][3];

    public GameBoard() {


        //Create new JFrame + Set Up Default Behaviour
        win = new JFrame("Tic Tac Toe");

        win.setBounds(0, 0, 195, 215);
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        win.setResizable(true);

        //Loop goes through each line of the array. It creates a new rectangle
        //determines it's colour based on modulus division
        //Add's the rectangle to the JPanel.
        for (int i = 0; i < rect.length; i++) {
            for (int j = 0; j < rect[i].length; j++) {
                rect[i][j] = new Rectangle(0, 0, 1, 1);
                if (count % 2 != 0) {
                    rect[i][j].setBackground(Color.black);
                } else {
                    rect[i][j].setBackground(Color.red);
                }
                panel.add(rect[i][j]);
                count++;
            }
        }


        //Sets the game to be visible.
        win.add(panel);
        win.setVisible(true);
        //userInput();
    }

    private void userInput() {
    Scanner scan = new Scanner(System.in);
    }
}
  • 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-12T07:09:26+00:00Added an answer on June 12, 2026 at 7:09 am

    Answer ended up being that I need to stick with the flow layout, manually size the rectangles and use a JLayeredPane instead. Was not aware this existed, talked to my lecturer who said that my thought process was right and that was the way he intended for me to do it……what a pain but all done thanks to those that helped.

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

Sidebar

Related Questions

Problem Hello all! I have this code which takes my jpg image loops through
hello all this seems to be my problem I have a table in mysql
Hello I currently have this code checking if a cookie exists, it works all
Hell All, So I have been facing this behavior for quite some time and
So my problem is this. I have a class called Globals that contains all
Hello all how can I create jar file of my project that is created
Hello i have the this problem, i need your help to figure out what
Hello I know all about http://www.php.net/manual/en/function.http-build-query.php to do this however I have a little
hello all i want to retrieve my all the wall post that i have
Hello all i have a simple problem i have a alertDialog and i want

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.