Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: To show a movement of a piece on a chessboard.

  1. #1
    Junior Member
    Join Date
    Feb 2024
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default To show a movement of a piece on a chessboard.

    Hi everybody.

    Here's my problem: I'm trying to code a GUI for a chess game. I want to ensure that when an AI plays, the user sees the piece of the chosen move moving.
    To do this, I change the coordinates of the piece and draw it in a JPanel which contains the chessboard. I refresh the screen regularly to get the movement of the piece.

    The piece moves very well, without aany problem, but other components than the chessboard (for example a list of notation of moves played) are impacted and cause strange and unexpected things.

    To refresh the screen regularly I use a timer which regularly calls the paintImmediately() method on the JPanel displaying the chessboard.

    I suspect that I must have done things incorrectly but I can't find a solution.

    Any help will be welcome.
    Thank you in advance.



    P.S. sorry for my english.
    P.S. I tried to attach an image to this message, but could not manage.
    Last edited by amauryxiv; February 12th, 2024 at 12:23 PM.

  2. #2
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    102
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: To show a movement of a piece on a chessboard.

    This would be on an applet. AWT container. I know how to play chess. The movements on the pond, only eats diagonal. But moves forward and not backward. Knight moves in a L shape route. Bishop moves only diagonal, but can go the whole board. The king is what you are trying to trap. Check mate. Queen, likewise moves diagonal and also side to side, the whole board. Rookie, moves up, down, side to side. So there are a number of combinations you movements you must add. And they can only occupy that space. No illegal movements. How many combinations did you come up with first on your problem? I'm interested too. GUI game on an applet.

  3. #3
    Junior Member
    Join Date
    Feb 2024
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: To show a movement of a piece on a chessboard.

    Hi Helium.
    Thank you for your answer.
    I know the rules of chess very well. My problem is not there.
    The problem is only graphic: the pieces move very well and I made sure that all the moves are legal.
    But at the end of the animation of the part which plays the part, the display of the window is disrupted as a whole...

Similar Threads

  1. Please help ! k Queens domination nxm chessboard problems.
    By bruce88 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 16th, 2012, 02:49 PM
  2. Using a while or do loop to represent the Rice and Chessboard case
    By WhyExist in forum Loops & Control Statements
    Replies: 10
    Last Post: October 12th, 2012, 10:39 AM
  3. How to control gain between mouse movement and cursor movement ?
    By DrPete in forum Java Theory & Questions
    Replies: 3
    Last Post: March 12th, 2012, 07:27 AM
  4. A chessboard with loops!
    By Hass in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 5th, 2011, 04:47 AM
  5. Chessboard filling issue
    By olemagro in forum AWT / Java Swing
    Replies: 7
    Last Post: January 23rd, 2010, 07:07 PM