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: Sudoku

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Location
    Pretoria
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sudoku

    Hi i am new in java. I am trying to create sudoku application bot I am strugling to connect classes

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.DisplayMode;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;

    import javax.imageio.ImageIO;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;


    public class MySudoku
    {
    public static byte[][] sudoku = new byte[729][82]; //global array for sudoku solution
    public static byte step = 0; //global variable for solution step

    private static final int WindowWidth = 777; //its 777 pixels wide
    private static final int WindowHeight = 636; //its 636 pixels high

    public static void ShowGUI()
    {
    Smethods.start(sudoku); //start array at step 0 has no numbers selected

    final byte border = 14; //border for display
    JFrame f = new JFrame("MySudoku");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    BufferedImage image = null;
    try {
    image = ImageIO.read(new File("sudoku.png"));
    } catch (IOException e) {
    }//end of try/catch
    f.setResizable(false); //not to be resized
    f.setIconImage(image);
    f.setSize(WindowWidth, WindowHeight); //size fixed by size of display and borders
    f.setLocation(0, 0); //start top left
    f.setLayout(new BorderLayout()); //north south east west and centre

    f.add(new SPanel(new Dimension(WindowWidth,border)), BorderLayout.NORTH);
    f.add(new SPanel(new Dimension(WindowWidth,border)), BorderLayout.SOUTH);
    f.add(new SPanel(new Dimension(border,WindowHeight)), BorderLayout.EAST);
    f.add(new SPanel(new Dimension(0,WindowHeight)), BorderLayout.WEST); //set the borders

    Component dp =new Component();
    dp.setBackground(Color.BLACK); //set the background of the sudoku display black
    f.add(dp, BorderLayout.CENTER); //add the sudoku display panel

    f.setVisible(true);
    }//end of show gui method

    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    ShowGUI();
    }
    }); //end of run()
    }//end of main
    }//end of MySudoku class

    public class Smethods
    {
    public static byte select(byte[][] sudoku, byte number, byte position, byte step)
    {
    if((sudoku[position*9 + number][step] == 0) || (sudoku[position*9 + number][step] > 9))
    return step;//end of number not possible or is selected

    step += 1; // we can select so write this step to the sudoku array
    int count = 0;
    for(count = 0; count < 729; count++)
    sudoku[count][step] = sudoku[count][step - 1]; //copy existing to next step
    for(count = 0; count < 9; count++)
    sudoku[position*9 + count][step] = 0; //Can't select any in box

    byte row = (byte) (position/9);
    for(count = 0; count < 9; count++)
    sudoku[row * 81 + count * 9 + number][step] = 0; //horizontal row

    byte column = (byte) (position%9);
    for(count = 0; count < 9; count++)
    sudoku[column * 9 + count * 81 + number][step] = 0; //vertical row

    int brow = (position/27)*243; //row block 0f 3
    column = (byte) (((position%9)/3)*27); //Column block of 3
    byte incount;
    for(incount = 0; incount < 3; incount++)
    {
    for(count = 0; count < 3; count++)
    sudoku[brow + column + count * 9 + incount * 81 + number ][step] = 0; //box of 3 x 3
    }//end of 3 x 3 box
    //we have selected one number
    sudoku[position*9 + number][step] = (byte) (number + 11); //selected now 11 to 19
    return step;
    }//end of select a number//end of class
    public static void start(byte[][] sudoku) {
    }
    public static void trysudoku(byte[][] sudoku, byte startstep) {
    }


  2. #2
    Member
    Join Date
    Feb 2014
    Location
    India
    Posts
    47
    My Mood
    Bored
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default Re: Sudoku

    Welcome! Please read this topic to learn how to post code correctly and other useful info for new members.

    Too much code posted improperly. Please fix it using the instructions in the link I've provided.

Similar Threads

  1. Sudoku
    By davasile in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2013, 12:18 AM
  2. Help with turning Sudoku into Magic Sudoku
    By Murlio in forum Java Theory & Questions
    Replies: 1
    Last Post: November 4th, 2012, 02:49 PM
  3. Help with Sudoku function please
    By peperez in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 14th, 2011, 12:40 AM
  4. Sudoku solver
    By Elliott50 in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 22nd, 2009, 02:03 PM
  5. Sudoku
    By mgutierrez19 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 30th, 2009, 10:09 PM