且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

数独板使用Java中JPanels

更新时间:2023-12-05 23:33:40

一对夫妇的事情,我看到:

A couple of things I see:

  • 我不认为你想9x9的的JP​​anel 译文]现在有,但9x9的的JTextField 秒。您可能需要3×3 的JP​​anel 取值这样就可以使每个部分的边界更大胆。它可能会更容易只是躺在这了明确,而不是试图做一个循环。

  • I don't think you want 9x9 JPanels as you have now, but 9x9 JTextFields. You may want 3x3 JPanels so you can make the borders of each section bolder. It might be easier to just lay these out explicitly instead of trying to do it in a loop.

您循环计数器(和数组的下标)应该从0开始,而不是1,你现在拥有它的方式,将循环只执行8次。

Your loop counters (and array indices) should start at 0, not 1. The way you have it now, the loops will only execute 8 times.

您会希望跟踪价值在每一行,列和每个3×3分小组。行和列是容易你有一个2D阵列中的方式。你可能会考虑持有的值在每个3×3区域阵列的另一个数组。这使得它更容易通过这些数值进行扫描,当你需要,而可能是有用的放置值较小的3×3 的JP​​anel S,如果你走这条路。

You are going to want to keep track of values in each row, column, and in each 3x3 sub-group. Rows and columns are easy the way you have it in a 2D array. You might consider another array of arrays that hold the values in each 3x3 area. This makes it easier to scan through these values when you need to, and might be useful for placing values in the smaller 3x3 JPanels, if you go that route.