Java 填字游戏应用程序 - 使用什么包?

发布于 2024-08-28 08:41:17 字数 136 浏览 11 评论 0原文

我即将创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尝蛊 2024-09-04 08:41:17

实际上,我认为您不需要网格方块中的文本字段,而只需写下每个网格单元格的每个字母。

为了允许编辑,您只需捕获您使用的组件上的键盘敲击,并根据用户编写的内容设置填字游戏单元格。

这样做会非常容易,因为您可以使用存储整个网格的二维数组,然后当用户选择一个定义时,只要从定义的第一个单元格开始键入键,您就开始填充单个字母。 .您的绘制例程只需要能够在单元格内绘制网格和中心字母,仅此而已。

JTable 可以工作,但它认为它对于您的问题来说太大了,因为您最终会与很多你根本不需要的东西交互。

编辑(供评论)

我做了类似的事情:
您可以拥有一个

class Cell
{
   boolean isBlank;
   char value;
}

包含单元格数组的单元格类,您可以获取网格:

Cell[][] gamefield = new Cell[15][15];

然后在 paint() 内,您可以轻松迭代:

for (int i = 0; i < Scheme.rows; ++i)
{
  for (int j = 0; j < Scheme.cols; ++j)
  {
    g2.drawRect(i*32, j*32, 32, 32);

    if (Scheme.scheme[i][j].isBlank)
      g2.fillRect(i*32 + 3, j*32 + 3, 32 - 5, 32 - 5);
  }
}

仅仅因为我仍然有屏幕截图结果,就像
替代文本

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

class Cell
{
   boolean isBlank;
   char value;
}

with an array of cells you obtain your grid:

Cell[][] gamefield = new Cell[15][15];

then inside paint() you can easily iterate:

for (int i = 0; i < Scheme.rows; ++i)
{
  for (int j = 0; j < Scheme.cols; ++j)
  {
    g2.drawRect(i*32, j*32, 32, 32);

    if (Scheme.scheme[i][j].isBlank)
      g2.fillRect(i*32 + 3, j*32 + 3, 32 - 5, 32 - 5);
  }
}

Just because I still have a screenshot result was something like
alt text

无声无音无过去 2024-09-04 08:41:17

也许对单元格使用 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.

岁月染过的梦 2024-09-04 08:41:17

您考虑过 JavaFX 吗? JavaFX 将允许您基于使用 Adob​​e 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文