Given that, you have many options to place your pieces on a chessboard. For instance, I use a GridLayout with JLabels as fields, and I put my pieces (png files) as icons of these JLabels. These JLabels are opaque, so it is easy to choose other colors for the fields, or to swap white and black.
However maybe it's some aggregration of square cells which fit inside an octagonal border. Who knows? It doesn't make sense to start designing code to display some particular view when you have no idea what the view looks like, so the first thing to do would be to find that out.
As for what you should know before starting out with a GridLayout, well... There's a lot you should know. Basic Swing programming would be helpful, for example. Basic Java programming, too. But since we have no idea what your abilities are, it's a bit hard to be specific.
As for questions about extends and implements, those are basic concepts which you will find in the Java™ Tutorials and just about any Java® textbook. You should understand those before you try anything advanced.
When filling the Grid with your Squares, in each corner make the six Squares fully transparant. That will give you the octagonal board in a very easy way.
But I must agree with Campbell: if terms like 'extends' and 'implements' mean nothing to you, do you think you are up to writing a chess program with GUI in Java?
As said, I would use an 11x11 chessboard, with the corner squares marked as invalid. Should not be a problem. One advantage: with only two pawn, miles apart, you probably won't be suffering from en passant problems.
Well, let us know if you have questions or problems. Success and enjoy!
But it's behind the toolbar instead of above it. Another thing is that the board covers the entire frame. I want the panel to be smaller than the actual frame.
I have yet to find a way to make the corners transparent yet. Still working on it.
A label can be made fully transparent by using the method setOpaque(false). All the labels that are part of the chessboard you would set the opaque property to true, and give each the correct background color.
and check in you nested for loop if an i, j combination is present in that List. For a Point the 'equals' method is already nicely redefined.
nadeera rajapakse wrote:Another problem is that the buttons that are not opaque can still be pressed. Does this method "getAccessibleContext()" help to make the JButton invalid?
A JLabel is much handier. Is there any particular reason why you would use a JButton?
hen, I create a dedicated inner Square class, like this
and finally I created the JPanel chessBoard, like
Piet Souris wrote:You are not actually using this illegalFields list. I had this in mind (sorry for giving a bit of code, but I hope you get what I had in mind)
Thank you, for giving me that bit of code!!! I'll work on this first for now, and get back to you if I have any other questions.