Hi, my name is Yang. My assignment for class is to create a sudoku program that will generate random numbers 1-9 in each of the 9 boxes and to run and compile correctly, also the button fields that holds the reset, solved, and hint button should be working as well. However I was able to create the 9 box sudoku and the button fields, the program does run, but it doesnt generate numbers to start with, also the buttons field do not activate at all, and not sure if i need to add more to codes to get the reset buttons to actually reset and etc...here are the codes.
//My Myframe class
//my Sudoku class
import java.awt.*; import javax.swing.*; import javax.swing.border.*; public class MySudoku extends JFrame{ public MySudoku() { JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(3,3)); Border boldLine = new LineBorder(Color.BLACK, 2); p1.setBorder(boldLine); for (int i=1; i <= 9; i++ ) { p1.add(new JTextField("")); } JPanel p2 = new JPanel(); p2.setLayout(new GridLayout(3,3)); p2.setBorder(boldLine); for (int i=1; i <= 9; i++ ) { p2.add(new JTextField("")); } JPanel p3 = new JPanel(); p3.setLayout(new GridLayout(3,3)); p3.setBorder(boldLine); for (int i=1; i <= 9; i++ ) { p3.add(new JTextField("")); } JPanel p4 = new JPanel(); p4.setLayout(new GridLayout(3,3)); p4.setBorder(boldLine); for (int i=1; i <= 9; i++ ) { p4.add(new JTextField("")); } JPanel p5 = new JPanel(); p5.setLayout(new GridLayout(3,3)); p5.setBorder(boldLine); for (int i=1; i <= 9; i++ ) { p5.add(new JTextField("")); } JPanel p6 = new JPanel(); p6.setLayout(new GridLayout(3,3)); p6.setBorder(boldLine); for (int i=1; i <= 9; i++ ) { p6.add(new JTextField("")); } JPanel p7 = new JPanel(); p7.setLayout(new GridLayout(3,3)); p7.setBorder(boldLine); for (int i=1; i <= 9; i++ ) { p7.add(new JTextField("")); } JPanel p8 = new JPanel(); p8.setLayout(new GridLayout(3,3)); p8.setBorder(boldLine); for (int i=1; i <= 9; i++ ) { p8.add(new JTextField("")); } JPanel p9 = new JPanel(); p9.setLayout(new GridLayout(3,3)); p9.setBorder(boldLine); for (int i=1; i <= 9; i++ ) { p9.add(new JTextField("")); } JPanel p10 = new JPanel(new GridLayout()); p10.setLayout(new GridLayout(3,3)); p10.add(p1); p10.add(p2); p10.add(p3); p10.add(p4); p10.add(p5); p10.add(p6); p10.add(p7); p10.add(p8); p10.add(p9); //Difficulty String[] difficulties = { "Easy", "Medium", "Hard" }; JComboBox difficultyBox = new JComboBox(difficulties); difficultyBox.setSelectedIndex(1); JPanel p11 = new JPanel(new GridLayout()); p11.setLayout(new GridLayout(5,1)); p11.add(new JButton("Reset"), BorderLayout.EAST); p11.add(new JButton("Hint"), BorderLayout.EAST); p11.add(new JButton("Solve"), BorderLayout.EAST); p11.add(new JButton("New Puzzle"), BorderLayout.EAST); p11.add(difficultyBox); add(p10, BorderLayout.CENTER); add(p11, BorderLayout.EAST); } }
1. I need to know how to get a few numbers to be generated into the 9 boxes without generating all the numbers.
2. I need to know how to get the buttons to do what it say to do, for instance, reset is to clear the boxes and start over. Hint, gives hint of what number is need to be place in the box, solve pretty much give the answer, and new puzzle is pretty much like reset, i would guess....
please help me solve this code......thanks....