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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:28:27+00:00 2026-06-11T16:28:27+00:00

I am programming a chess game in java, and at the moment I am

  • 0

I am programming a chess game in java, and at the moment I am building a basic interface. It is simply an 8×8 array of buttons that will display in a window. I have coded for these buttons, and have gotten the board to display properly. However, when I connect this with the rest of the game, the game window crashes upon running and I have to force quit the java application. This is my code:

package Chess_Game; 
import javax.swing.SwingUtilities;
import Chess_Interface.Iboard;

public class Game_Tester 
{
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable() 
        {
            public void run() 
            {
                    Game G = new Game();
                    Iboard I = new Iboard(G.getBoard().getArray(), G.getSides());
                    I.setVisible(true);
                    while(!(G.isGameOver()))
                    {
                        boolean redo = true;
                        while(redo)
                        {
                            int row = 0; 
                            int col = 0; 
                            int nRow = 0; 
                            int nCol = 0;
                            System.out.println("Click the piece you want to move.");
                            while(!(I.getBool())){}
                            if(I.getBool())
                            {
                                row = I.getRow();
                                col = I.getCol();
                                I.setBool(false);
                            }
                            System.out.println("Click the place you want to move to.");
                            while(!(I.getBool())){}
                            if(I.getBool())
                            {
                                nRow = I.getRow();
                                nCol = I.getCol();
                                I.setBool(false);
                            }
                            if(G.canMove(row, col, nRow, nCol))
                            {
                                G.move(row, col, nRow, nCol, I);
                                redo = false;
                            }
                            else
                            {
                                System.out.println("You cant move there! Try again!");
                            }
                        }
                        I.updateBoard(G.getBoard().getArray(), G.getSides());
                    }
            }
        });
    }
}

The board displays properly when I comment out the main while loop (and everything inside of it), and I assume the problem lies somewhere inside there, but I have been unable to find it. I have also looked online for similar game loop problems, but all of those have been for games involving frame rates and movement across a java swing frame, something that is not present in my code.

Any help 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-11T16:28:29+00:00Added an answer on June 11, 2026 at 4:28 pm

    You have several loops such as

    while(!(I.getBool())){}
    

    which could potentially run forever if I does not respond as expected. You could start by printing something out within these loops, and within the following blocks if(I.getBool()){...} to see at what point your application gets stuck.

    Checking the user interface in a loop like this is not good practice. It is better to use Listeners to respond to the user interface.

    Nor is running the main application on the Swing thread using SwingUtilities.invokeLater(new Runnable(), even though it avoids potential problems of updating the GUI from another thread.

    In fact, this may be your root problem, as running the main application loop on the Swing thread (the thread used to run the GUI) like this probably prevents the GUI from ever responding properly. You are putting a task (the entire game) onto the GUI’s queue, but that task never completes while(!(G.isGameOver())).

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

Sidebar

Related Questions

Programming language: Java Ok, so I want to have a BufferedImage that keeps rotating
Hi I have been learning Java Swing for creating a chess game to practice
I'm programming a King Chess game on the iPhone. When the user touches a
I am programming an AI for a chess-like game, based on two types of
While programming in java is there any time that I as the programmer should
Programming language books usually explain that value types are created on the stack, and
There are 4 months since I stopped developing my Silverlight Multiplayer Chess game. alt
Programming in Java, what's the better way to create resource files to save the
When programming in OS X, one of the great annoyances to me is that
While programming under eclipse+PyDev and using Flask framework, I noticed that the auto-organizing imports

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.