Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Creating a Sudoku Program Assignment

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating a Sudoku Program Assignment

    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

     
    import javax.swing.JFrame;
     
    public class MyFrame {
        public static void main(String[] args) {
            JFrame frame = new MySudoku();
            frame.setTitle("My Sudoku");
            frame.setSize(400,300);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    }

    //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....
    Last edited by xion0374; February 17th, 2012 at 08:05 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Creating a Sudoku Program Assignment

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting

    Please explain what you need help with by asking specific questions.

Similar Threads

  1. Can anyone help me finish creating a GUI for my program
    By danbendlin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 16th, 2012, 07:34 PM
  2. I'm creating a sudoku program that is somehow in an infinite loops.
    By Leiferson in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 18th, 2011, 03:21 AM
  3. Need help with creating Program
    By apescato in forum Java Theory & Questions
    Replies: 4
    Last Post: October 20th, 2011, 07:46 PM
  4. [SOLVED] Compile a set of java files for a sudoku program
    By kanishk.dudeja in forum Java Theory & Questions
    Replies: 7
    Last Post: June 16th, 2011, 09:54 AM
  5. Need help creating this program
    By ixjaybeexi in forum File I/O & Other I/O Streams
    Replies: 25
    Last Post: October 19th, 2009, 07:08 AM