As explained in the introduction section of this tutorial, the code posted in this article will only help you drawing a chess board, placing pieces at the proper positions and making moves of the pieces. If you are interested in more advanced features then this article might not be able to help you. In order to run the following code you need JVM (Java Virtual Machine) running on your computer. Java can be downloaded and installed from the following website:

Before I post the code, let me show you the screenshots of the application after it is built:

After you compile and run the application, the window shown above will be displayed. Since white pieces are arranged in the bottom section, it means you’ve been assigned white color. Now you can select any piece and piece will turn gray as shown in the following screenshot:

After selecting your piece you can move it anywhere in the board. As shown in the following screenshot:

Actually right now, since move validity is not being checked, you can even take your own piece even. But let’s not do it for now. Alright folks, that’s all for today, enjoy the following code and if you need, ask me for the whole project, ciao…

Like this:

Hi Mukarram, I like the looks of your chessboard but I can only replicate the board itself as I don’t have access to the icons for the different pieces. Is it possible to send these to me through email please?

Good day Mukarram,i really appreciate your post but i need a favour from you i have similar project but mine is on processing may be you have heard of it it uses java syntax could you help me with the code of creating the board nd how to validate each piece.you would be a life saver

Hi Rabiu, as much as I would love to help you, it is really very hard for me to provide solutions for everybody over the internet. If you please explain further on what exactly your project requirements are then perhaps I would be able to provide some help.

Mukarram Mukhtar,
Can you please email me the whole source code, i tried to runi it but i need the image icon.. please I need it urgently, i want to debug it and understand the steps.. get back to me ASAP please 🙂

hi
would u plz teach me from the very begining how to create a project and
where to write these codes,i really need help , does this code need a jframe
or it is created by the codes ,i mean we should ourself add a jframe or not !
and would u plz send your whole project for me??
thanks alot

I am currently working on phase 3 of a semster long project to create a chess application in java and I am absolutely struggling. I would greatly appreciate any help. I am new to programming and new to these forums. May I please view your code to use as a reference for building my project? Thanks for your consideration.

I was deeply impressed with the description and images of your chess board program. Can you please send me the whole project code, with icons? I would greatly appreciate it. I am building a chess robot with lego nxt, and wanted to have a simple chess gui to check the board onscreen, compared to real life. Thank you kindly. I would of course cite your program in our chess robot. Many thanks in advance.

I have been building a chess program of my own and was looking around for an example of how to draw a chessboard in Java.
I got your example to run in Eclipse, but I don’t have the icons for displaying the pieces. Is there any way you could send
me the png files for the icons. Many thanks in advance. I’d appreciate it very much.

hi Mr Mukarram Mukhtar
Thank you for the tutorial very, interresting work. Having difficulties getting the icons to appear on the board.
Please could you help, maybe with the code that will allow the icon to appear

i really liked ur code !!its easy to understand.bt i cannot see icons in the chessboard.i have to make project for my college.can u please send me the whole project with icon.? thank you in advance.will wait for ur reply………:)

Raymond, the division by 57 is because the pnlMain’s width and height is 460 pixels and pnlMain is divided into 64 equal panels (horizontally and vertically), now wherever user clicks to make a move, we have to convert the X and Y of the cursor into the x and y index of a 2-dimensional array strChessBoard. These exact numbers are not mandatory, you can change these numbers if you change the size of the board etc. Try playing around with these numbers, only then you’ll understand what I’m talking about. Good luck! 🙂

The black pieces will be moved by opponent, in this case, the computer. While in the complete game computer will have the ability to make moves, in this particular demo, I was just showing how to quickly and easily draw a chess board in JAVA. This can give you guys a head start if you’re writing a chess game of your own. I’ll be more than happy to send you the source code if you’re interested. Lemme know 🙂

Sorry, I have created the folder “images” and put all of image icons into it, then put the folder in the same folder with the source code, but there haven’t been any icon displayed at all. How can I do now ? 😦

I’ve sent you the project source code in a zip file. It has images folder and everything set up. You can then replace my images with yours. the name of the image files and their extension MUST be the same as given in the source code. I hope that helps.

Hi Mukarram,
I am making chessmaster club as my final year projec, here i want make player’s to play game.using website so i requried client-server architecture for multiple player, so please i need your valuable help in this, and one more thing, those player who want to watch the game can watch it live please also suggest me for this, and thank you in advance

Hey Mukkaram, I looked at your code and looks like it can be helpful for my assignment. However my assignment does not require GUI, but it will help me implement the methods and objects. Is it possible for you to send me the code. I will be very thankful to you.