我知道已经有几篇关于数独相关问题的帖子,但我不确定它们中是否有任何我正在寻找的...
我正在尝试使用JPanels和JTextfields在Java中构建一个空的Sudoku板.我还需要在右侧创建一个带有另一个JPanel的菜单.
该板本身是一个9 x 9的正方形,分为9个3x3正方形.请注意,每个较小的正方形都由比正常的方形边框更重的边框设置.每个方块都是一个文本字段.编写程序,以便文本字段中没有任何内容.用户可以根据需要输入文本字段,如果需要,则会显示数字.在侧面有四个按钮,可以让你解决,获得一个新的拼图,获得提示,或重置拼图.
任何想法都会很棒.我无法理解如何嵌套for循环来创建电路板.这是我的代码......
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
public class ArrayTest extends JFrame {
public ArrayTest() {
JPanel board = new JPanel(new GridLayout(9, 9));
add(board);
JPanel[][] squares = new JPanel[9][9];
Border border = BorderFactory.createLineBorder(Color.BLACK);
for (int row = 1; row < 9; row++) {
for (int col = 1; col < 9; col++) {
squares[row][col] = new JPanel();
board.add(squares[row][col]);
}
}
JPanel menu = new JPanel();
menu.add(new JButton("Reset"));
menu.add(new JButton("Hint"));
menu.add(new JButton("Solve"));
menu.add(new JButton("New Puzzle"));
add(menu); …Run Code Online (Sandbox Code Playgroud)