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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:01:51+00:00 2026-05-22T20:01:51+00:00

I am writing a Reversi application. I implemented the turns manager class, but I

  • 0

I am writing a Reversi application. I implemented the turns manager class, but I have a little problem in the while loop.

This is my snippet:

while (!table.isFull() || passFlag != 2) {
    if (player1.isActive()) {
        for (int i = 0; i < table.getSize(); i++) {
            for (int j = 0; j < table.getSize(); j++) {
                table.getField(i, j).addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent e) {
                                if (e.getSource() instanceof Field) {
                                    ((Field) e.getSource()).changeToBlack();
                                }
                            }
                        });
            }
        }
    }
    if (player2.isActive()) {
        for (int i = 0; i < table.getSize(); i++) {
            for (int j = 0; j < table.getSize(); j++) {
                table.getField(i, j).addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent e) {
                                if (e.getSource() instanceof Field) {
                                    ((Field) e.getSource()).changeToWhite();
                                }
                            }
                        });
            }
        }
    }
    sentinel.changeActivePlayer(player1, player2);

The table is a grid of buttons, and the fields are the buttons. The loop does not wait for the player interaction. How can I implement the code so that it waits for the user’s mouse click?

This is the full code of this class

package Core;

import GUILayer.Field;
import GUILayer.MainFrame;
import elements.Player;
import elements.Table;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TurnManager {

    int passFlag = 0;
    int TurnFlag = 0;
    Sentinel sentinel = new Sentinel();

    public TurnManager() {
    }

    public void manage(MainFrame mainframe, Table table, Player player1, Player player2) {

        while (!table.isFull() || passFlag != 2) {
            if (player1.isActive()) {
                for (int i = 0; i < table.getSize(); i++) {
                    for (int j = 0; j < table.getSize(); j++) {
                        table.getField(i, j).addActionListener(
                                new ActionListener() {

                                    public void actionPerformed(ActionEvent e) {
                                        if (e.getSource() instanceof Field) {
                                            ((Field) e.getSource()).changeToBlack();
                                        }
                                    }
                                });
                    }
                }
            }
            if (player2.isActive()) {
                for (int i = 0; i < table.getSize(); i++) {
                    for (int j = 0; j < table.getSize(); j++) {
                        table.getField(i, j).addActionListener(
                                new ActionListener() {

                                    public void actionPerformed(ActionEvent e) {
                                        if (e.getSource() instanceof Field) {
                                            ((Field) e.getSource()).changeToWhite();
                                        }
                                    }
                                });
                    }
                }
            }
            sentinel.changeActivePlayer(player1, player2);
        }
    }
}
  • 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-05-22T20:01:51+00:00Added an answer on May 22, 2026 at 8:01 pm

    This is not a complete solution, but your code should look more like this. I think it is a good starting point to hack things together. Hope this helps.

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    public class TurnManager implements ActionListener{
    
        int passFlag = 0;
        int TurnFlag = 0;
        Sentinel sentinel = new Sentinel();
        Player player1,player2;
    
    
        public TurnManager(MainFrame mainframe, Table table, Player p1, Player p2) {
            player1 = p1;
            player2 = p2;
            for (int i = 0; i < table.getSize(); i++) {
                for (int j = 0; j < table.getSize(); j++) {
                    table.getField(i, j).addActionListener(this);
                }
            }
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof Field) {
                Field field = ((Field) e.getSource());
                //implement logic here, for example:
                if (table.isFull())
                    throw new RuntimeException("Table full! Stop! STOP!");
    
                if (player1.isActive())
                    field.changeToBlack();
                if (player2.isActive())
                    field.changeToBlack();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a plug-in for an application where I have a custom class that
Writing a python program, and I came up with this error while using the
I need a CRC check for an application Im writing, but cant figure out
I have an application where I want two users to communicate with eachother.. This
I'm exploring the possibility of writing an application in Erlang, but it would need
I'm writing a structural modeling tool for a civil enginering application. I have one
We are writing an ASP.NET MVC application and every once in a while we
I'm writing a project for a Python coding class and I have a question.
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing a .NET DLL how do I find Application.ProductName ? EDIT: Obviously, importing Windows.Forms

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.