我正在为数独开发 GUI。我的 Droid (SudokuFree) 有一个很好的应用程序,我想复制它的功能并添加一个小功能(保存一个正在进行的板,继续,如果需要,可以恢复)。部分代码已被注释掉,使其更像 SSCCE,如果您有问题,请参阅第二篇文章。两个帖子对我帮助很大,我从他们那里借了很多下面的代码。
我的问题是 JButtons 仅在被碾压后才可见。我搜索了以前的帖子,只找到了对 setVisible(true) 的引用,我已经这样做了。
谢谢
public class RunSudokuNinja implements Runnable{
@Override
public void run() {
//SudokuEngineInterface sudokuEngine = new SudokuEngine();
SudokuView sudokuView = new SudokuView();
//sudokuView.setSudokuImplementation(sudokuEngine);
sudokuView.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new RunSudokuNinja());
}
}
public class SudokuView extends JFrame{
//SudokuController controller;
//SudokuEngine sudokuEngine;
private static final int width = 500;
private static final int height = 650;
private static final int yMar = 100;
private static final int xMar = 25;
private static final int cellSize = 40;
private static final int gridSpace = 3;
private static final int secSpace = 9;
public JButton[][] btnz = new JButton[9][9];
public SudokuView() {
//controller = new SudokuController();
//sudokuEngine = new SudokuEngine();
setTitle("Sudoku Ninja 0.1");
setSize(width, height);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setBackground(Color.GRAY);
int y=yMar;
for (int r=0;r<9;r++){
int x=xMar;
for (int c=0;c<9;c++){
btnz[r][c]=new JButton("1");
btnz[r][c].setBounds(x,y,cellSize,cellSize);
btnz[r][c].setVisible(true);
add(btnz[r][c]);
if (c==2||c==5){
x = x+cellSize+secSpace;
}else{
x = x+cellSize+gridSpace;
}
}
if (r==2||r==5){
y = y+cellSize+secSpace;
}else{
y = y+cellSize+gridSpace;
}
}
setVisible(true);
}
@Override
public void paint(Graphics g){
}
public void setSudokuImplementation(SudokuEngineInterface listener) {
//controller.setListener(listener);
}
}