Results 1 to 3 of 3
  1. #1
    easyp is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default Persistence causing problems with JButton 2D Array

    Hi there, I'm new here and I'm hoping you can help

    For a student project I am creating a sudoku game which uses a 2D array of integers called model[][] and then a solving algorithm reads from this array, computes the solution and then updates a 2D array of JButtons called view[][] which the user can enter numbers. Most of the the functions read from this array to update the "model" and then the view of JButtons is updated so the user can see.

    I'm using persistance to store the model[][] 2D integer array and then a load button reads the file and writes this back to the model[][]

    Whenever I click my load button my updateView method seems to update the view correctly and the user can see the loaded cells but if I do something else such as start a new game or click solve (which then reads from this array and solves) the console output seems to suggest everything is working fine but my 2D array of JButtons on screen do not.

    The program behaves differently for some reason after clicking load and anything else I do does not update the view correctly

    Is anyone able to help me? I can send you my code. I would really appreciate it if you could.


    Here's the code for the save and load operation

    if(event.getSource()== save || event.getSource()== saveItem){

    hintButton.setVisible(true);
    hintItem.setVisible(true);

    try {
    FileOutputStream fos = new FileOutputStream("Save");
    ObjectOutputStream out = new ObjectOutputStream(fos);
    out.writeObject(model);
    out.flush();
    out.close();
    }
    catch (IOException e) {
    System.out.println(e);
    }
    }

    if(event.getSource()== load || event.getSource()== loadItem ){

    hintButton.setVisible(true);
    hintItem.setVisible(true);

    clearCells();
    backgrounds();


    try {
    FileInputStream fis = new FileInputStream("Save");
    ObjectInputStream in = new ObjectInputStream(fis);
    model = (int[][])in.readObject();
    in.close();

    updateView();

    }
    catch (Exception e) {
    System.out.println(e);
    }
    // return null;


    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Welcome to the forum, and I hope that your problem get's solved, but in an effort to prevent unnecessary duplication of effort and disjointed discussion, please do not cross-post without being upfront about it. Thank you for your cooperation.

Similar Threads

  1. Array problems!
    By Addez in forum New To Java
    Replies: 4
    Last Post: 08-29-2009, 07:56 PM
  2. Problems with ActionEvent for JButton
    By TrueBear in forum AWT / Swing
    Replies: 1
    Last Post: 08-24-2009, 05:26 PM
  3. Array problems..
    By smokeviolent in forum New To Java
    Replies: 1
    Last Post: 04-17-2009, 07:45 AM
  4. Array problems
    By Hosticus in forum New To Java
    Replies: 2
    Last Post: 01-18-2009, 03:48 AM
  5. Problems with jButton ActionPerformed
    By susan in forum AWT / Swing
    Replies: 3
    Last Post: 08-07-2007, 05:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •