开发者

Java Crossword Application - what package to use?

I'm about to create a java crossword application but I am unsure of what packages to use to draw the cr开发者_StackOverflow社区ossword 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.


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

Java Crossword Application - what package to use?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜