I just started working on GUI components and I'm trying to create a Sudoku board. It doesn't need to be functional yet. I am just trying to get the layout. Anyone know why this code isn't producing a blank 81 square board? I am just getting a blank JFrame. I feel like my nested for loop should work, but I'm getting nothing. Any suggestions would be appreciated.
Thanks,
Adam
import javax.swing.*;
import java.awt.*;
public class SudokuTest extends JFrame {
public SudokuTest() {
JTextField smallSquare = new JTextField(1);
JPanel smallPanel = new JPanel();
smallPanel.setLayout(new GridLayout(3, 3));
JPanel largePanel = new JPanel();
largePanel.setLayout(new GridLayout(3, 3));
for (int i = 1; i <= 9; i++) {
largePanel.add(smallPanel);
for (int j = 1; j <= 9; j++) {
smallPanel.add(smallSquare);
}
}
smallPanel.add(smallSquare, BorderLayout.CENTER);
largePanel.add(smallPanel, BorderLayout.CENTER);
}
public static void main(String[] args) {
/** Create a frame and set its properties*/
JFrame frame = new SudokuTest();
frame.setTitle("Sudoku Test");
frame.setSize(600, 600);
frame.setLocationRelativeTo(null); //Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

New Topic/Question
Reply




MultiQuote



|