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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:57:41+00:00 2026-06-07T05:57:41+00:00

Hello im new here i am making a small tictactoe game where i have

  • 0

Hello im new here i am making a small tictactoe game where i have made a gui as follows:

public static void main(String[] args) {

    Frame frame1 =new Frame("TickTacToe");
    frame1.setLayout(null);
    frame1.setBounds(250,150,500,500);
    frame1.setVisible(true);
    frame1.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e){
            System.exit(0);
        }
    });

    final Button button11 = new Button("");
    button11.addActionListener(null);

    final Button button12 = new Button("");
    button11.addActionListener(null);

    final Button button13 = new Button("");
    button11.addActionListener(null);

    final Button button21 = new Button("");
    button11.addActionListener(null);

    final Button button22 = new Button("");
    button11.addActionListener(null);

    final Button button23 = new Button("");
    button11.addActionListener(null);

    final Button button31 = new Button("");
    button11.addActionListener(null);

    final Button button32 = new Button("");
    button11.addActionListener(null);

    final Button button33 = new Button("");
    button11.addActionListener(null);


    button11.setBounds(100, 100, 80, 70);
    button12.setBounds(100, 200, 80, 70);
    button13.setBounds(100, 300, 80, 70);
    button21.setBounds(200, 100, 80, 70);
    button22.setBounds(200, 200, 80, 70);
    button23.setBounds(200, 300, 80, 70);
    button31.setBounds(300, 100, 80, 70);
    button32.setBounds(300, 200, 80, 70);
    button33.setBounds(300, 300, 80, 70);

    frame1.add(button11); 
    frame1.add(button12); 
    frame1.add(button13); 
    frame1.add(button21); 
    frame1.add(button22); 
    frame1.add(button23); 
    frame1.add(button31); 
    frame1.add(button32);
    frame1.add(button33); 
}

I want to add action listeners to the buttons but not in this void ideall even a different class so i can create a way to run a loop of functions such as a player turn changer where if it is turn one it will set button text to x and o if it is the otheI know more orless the code i would need to use but i cant figure out a way to use the gui from anzwhere else than its own void. I dont quite know what im searching for so any help is much 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-07T05:57:42+00:00Added an answer on June 7, 2026 at 5:57 am

    First of all, this program structure is pretty bad. From the looks of it I can tell you came from a procedural programming language like C or Basic or something of the sort. Java is all about Object Oriented architecture. Java can run procedurally but it was not meant to be. First thing that I would start with is get out of main(). Here is a good way to do that:

    public class TicTacToe
    {
        public TicTacToe()
        {
    
        }
    
        public static void main(String args[])
        {
            new TicTacToe();
        }
    }
    

    TicTacToe might seem simple but it has a lot of things going on at once, people are clicking buttons so you need ActionListeners, you need to update the UI of the screen after every move, you need to check to make sure each move is valid, you need to check for a win after every move and much much more. This is almost impossible to do inside of main.

    It’s generally a bad idea to add any sort of Component straight into a JFrame. Its better to put a JPanel inside of a JFrame and then add the components to the JPanel.

    Try making a class structure for your game. Here is what I would do:

    TicTacToe.class --> Checks rules, checks for wins and starts and stops game
    Player.class (implements ActionListener) --> Listens for each Player's input
    Board.class (extends JPanel) --> this will display the components for the game
    Computer.class (extends Player) --> if you wanted to create an AI this is where you would do so
    

    If I was you I would read a book about Java Game Development or take a class. If you want to get good at Java that is a good place to start. Your missing a lot of crucial knowledge that you need to do even a simple task such as make a TicTacToe game.

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

Sidebar

Related Questions

hello i am new here and i hope i don`t post in a wrong
I am new here so hello. I am using ASP.NET 4 and I am
hello im new to python and have been reading over the documentation and am
Hello.Am new to ios development.What have to do for NSOpenPanel to work in the
I have a method which returns different types of instances (classes): public [What Here?]
For example, here's my Hello machine: hello_machine = new HelloMachine; At this point, if
class Hello @hello = hello def display puts @hello end end h = Hello.new
Hello I'm new to Joomla and I want to change the way an account
Hello i am new in android and i am developing one application in which
hello I'm new to PHP programming and I migrated from ASP .net to PHP..

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.