简体   繁体   English

如何制作 JButton 的棋盘

[英]How to make a checkerboard of JButtons

I need to make a checkerboard that is composed of alternating black and white JButtons, that are right up against another.我需要制作一个由交替的黑白 JButton 组成的棋盘,这些 JButton 彼此相对。 Can I use the graphics class to add buttons?我可以使用图形class来添加按钮吗? I would appreciate help not answer as this is homework.我很感激帮助不回答,因为这是家庭作业。

Take a look at the GridLayout you can find examples on how to use ithere .查看GridLayout ,您可以在此处找到有关如何使用它的示例。 Lastly, I think that using JPanels will give you a better finish than using JButtons if you want to create a checkered board, but that is entirely up to you.最后,我认为如果您想创建方格板,使用 JPanels 比使用 JButtons 效果更好,但这完全取决于您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM