Java 填字游戏应用程序 - 使用什么包?
我即将创建一个 java 填字游戏应用程序,但我不确定使用哪些包来绘制填字游戏网格。我知道您可以使用 Graphics2D 等手动绘制网格,但我不确定这是否是最简单的方法,因为我需要网格方块中的文本字段。
任何人对创建填字游戏网格有任何建议。
I'm about to create a java crossword application but I am unsure of what packages to use to draw the crossword grid. I know you can manually draw grids with Graphics2D etc. but I'm not sure if this is the easiest way to do it as I'll need text fields in the grid squares.
Anyone have any suggestions as to creating the crossword grid.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,我认为您不需要网格方块中的文本字段,而只需写下每个网格单元格的每个字母。
为了允许编辑,您只需捕获您使用的组件上的键盘敲击,并根据用户编写的内容设置填字游戏单元格。
这样做会非常容易,因为您可以使用存储整个网格的二维数组,然后当用户选择一个定义时,只要从定义的第一个单元格开始键入键,您就开始填充单个字母。 .您的绘制例程只需要能够在单元格内绘制网格和中心字母,仅此而已。
JTable
可以工作,但它认为它对于您的问题来说太大了,因为您最终会与很多你根本不需要的东西交互。编辑(供评论):
我做了类似的事情:
您可以拥有一个
包含单元格数组的单元格类,您可以获取网格:
然后在
paint()
内,您可以轻松迭代:仅仅因为我仍然有屏幕截图结果,就像
Actually I don't think you need textfields in the grid squares but just to write down every single letter for every grid cell..
To allow editing you just catch keyboard strokes over the component you use and set crossword cells according to what the user writes.
Doing it this way would be quite easy because you can use a back 2-dimensional array that stores the whole grid, then when the user select a definition you just start filling single letters whenever keys are typed starting from the first cell of the definition.. your draw routine will need just to be able to draw the grid and center letters inside cells, nothing more..
A
JTable
could work but it think it's oversized for your problem, because you'll end up interfacing with a lot of things you don't need at all..EDIT (for comment):
I did it something similar this way:
you can have a cell class
with an array of cells you obtain your grid:
then inside
paint()
you can easily iterate:Just because I still have a screenshot result was something like
也许对单元格使用 JTable 和自定义渲染器。这至少应该是一个简单的解决方案。当然,习惯 JTable 需要一点时间,但最终它会变得非常简单。
Maybe use a JTable and custom renderer for the cells. That should be at least a simple solution. Of course it takes a little time to get used to JTable, but eventually it's quite simple.
您考虑过 JavaFX 吗? JavaFX 将允许您基于使用 Adobe Photoshop/Inkscape 等编辑的矢量/图形创建“场景图”。
如果没有,最简单的方法是扩展 JTextField,使其仅容纳 1 个字符,并且为黑色/或任何颜色指示不可编辑和禁用。另外,添加自定义边框来指示拼图问题编号。将所有内容放入 GridLayout 中。
Did you consider JavaFX at all? JavaFX will let you create "scene-graphs" based on vector/graphics edited using Adobe Photoshop/Inkscape etc.
If not, most simple way would be to extend JTextField such that that will just hold 1 char and will be black/or whatever color to indicate non-editable and disabled. Also, add a custom Border to indicate puzzle question number. Put everything in to a GridLayout.