Results 1 to 15 of 15
  1. #1
    mallowgirl12 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Smile SlidingBlockModel

    hi guys

    im doing a slidingblockmodel, i have done three tasks, but in the next task am recieving one error only. here's the error, i don't know what to do, i've tried, but it stilll appears on one error. hope someone will be able to help me here

    C:\Users\123\Documents\Workshop5\Task4\SlidingBloc kModel.java:50: not a statement
    puzzle[empty_col][empty_row];
    ^
    1 error

    Tool completed with exit code 1

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

  3. #3
    mallowgirl12 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default the full code

    Java Code:
    import java.awt.image.*;
    import javax.imageio.*;
    import java.io.File;
    
    public class SlidingBlockModel
    {
    BufferedImage original_image; // the image to be cut up into blocks
    int numCols; // number of columns in the grid of blocks
    int numRows; // number of rows in the grid of blocks
    int empty_col; // holds the column index of the one empty grid element
    int empty_row; // holds the row index of the one empty grid element
    BufferedImage[][] puzzle; // the two '[][]' allows a 2-D array
    				  // to be created - each element is an image
    
    
    
    public SlidingBlockModel(int numcols, int numrows, String fname)
    {
    String image_filename = fname;
    
    try
    {
    original_image = ImageIO.read(new File(image_filename));
    System.out.println("image " + image_filename + " loaded in ok." );
    System.out.println("image width is: " + original_image.getWidth() + " image height is: " + original_image.getHeight());
    }
    catch (Exception e)
    {
    System.out.println("Sorry - couldn't load in file " + image_filename);
    }
    }
    private BufferedImage getImageRect(int thisCol, int thisRow)
    {
    // if input is out of range, return "null"
    // otherwise, make and return the Rectangle
    int w = original_image.getWidth()/numCols;
    int h = original_image.getHeight()/numRows;
    int x = thisCol*w;
    int y = thisRow*h;
    return original_image.getSubimage(x,y,w,h);
    }
    
    public static void main(String[] args)
    {
    SlidingBlockModel myModel; newSlidingBlockModel(numCols,numRows,"my_image.jpg");
    
    myModel = new SlidingBlockModel(5, 4, "..\\computer.jpg");
    
    BufferedImage newImge = myModel.getImageObserver(1,1);
    puzzle[empty_col][empty_row];
    puzzle = new BufferedImage[numCols][numRows];
    empty_row = 0;
    empty_col = 0;
    puzzle[empty_row][empty_col] = null;
    BufferedImage getSubimage(int thisCol, int thisRow);
    System.out.println("image width is: " + newImg.getWidth() + " image height is: " + newImg.getHeight());
    }
    }
    the full code
    Last edited by Fubarable; 03-13-2011 at 01:30 PM.

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

    Default

    Code tags added, but your code is still not easily read as you've posted unformatted code. Please edit your post above and post your original formatted code (with indentations). If you put in the effort to make it easier for us to read your code, easier for us to help you, we'll more likely put in the effort to try to help you.

  5. #5
    mallowgirl12 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    import java.awt.image.*;
    import javax.imageio.*;
    import java.io.File;

    public class SlidingBlockModel
    {
    BufferedImage original_image; // the image to be cut up into blocks
    int numCols; // number of columns in the grid of blocks
    int numRows; // number of rows in the grid of blocks
    int empty_col; // holds the column index of the one empty grid element
    int empty_row; // holds the row index of the one empty grid element
    BufferedImage[][] puzzle; // the two '[][]' allows a 2-D array
    // to be created - each element is an image

    public SlidingBlockModel(int numcols, int numrows, String fname)
    {
    numCols = numcols;
    numRows = numrows;
    String image_filename = fname;

    try
    {
    original_image = ImageIO.read(new File(image_filename));
    System.out.println("image " + image_filename + " loaded in ok." );
    System.out.println("image width is: " + original_image.getWidth() + " image height is: " + original_image.getHeight());
    }
    catch (Exception e)
    {
    System.out.println("Sorry - couldn't load in file " + image_filename);
    }
    }
    private BufferedImage getImageRect(int thisCol, int thisRow)
    {
    // if input is out of range, return "null"
    // otherwise, make and return the Rectangle
    int w = original_image.getWidth()/numCols;
    int h = original_image.getHeight()/numRows;
    int x = thisCol*w;
    int y = thisRow*h;
    return original_image.getSubimage(x,y,w,h);
    }

    public static void main(String[] args)
    {
    SlidingBlockModel myModel;

    myModel = new SlidingBlockModel(5, 4, "..\\computer.jpg");

    BufferedImage newImg = myModel.getImageRect(1,1);
    puzzle = new BufferedImage[numCols][numRows];
    puzzle[empty_col][empty_row];
    System.out.println("image width is: " + newImg.getWidth() + " image height is: " + newImg.getHeight());
    }

    }


    included with the error

    C:\Users\123\Documents\Workshop5\Task3\SlidingBloc kModel.java:51: not a statement
    puzzle[empty_col][empty_row];
    ^
    1 error

    Tool completed with exit code 1

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

    Default

    You're trying to directly access your class fields, which are instance fields from a static method, and this is not allowed. You can access them if you create an object of the class, e.g.

    Java Code:
    public static void main(String[] args) {
       SlidingBlockModel sbm = new SlidingBlockModel(6, 6, "foo");
       sbm.empty_row = 0;
    }

    But you really don't want to do this either. Why not do some of what you're trying to do in the main method in the SlidingBlockModel constructor instead?

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

    Default

    Don't forget to use code tags when posting code. Please see the first link in my signature below on how to do this. You don't have to create another post here, but instead you can edit one of your posts above.

  8. #8
    mallowgirl12 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    Thanks, so i just need to change something in the code provided?

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

    Default

    Quote Originally Posted by mallowgirl12 View Post
    Thanks, so i just need to change something in the code provided?
    You need to edit your post to add code tags. To fix your code, yeah, you'll need to make lots of changes. For one throw out your main method and rewrite it so that it doesn't try to access instance variables directly.

  10. #10
    mallowgirl12 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    C:\Users\123\Documents\Workshop5\Task3\SlidingBloc kModel.java:45: illegal start of expression
    SlidingBlockModel myModel; = new SlidingBlockModel(6,6, "foo");
    ^
    C:\Users\123\Documents\Workshop5\Task3\SlidingBloc kModel.java:51: not a statement
    puzzle[empty_col][empty_row];
    ^
    2 errors

    Tool completed with exit code 1

    the new error

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

    Default

    If you've changed your code and gotten this error, then you need to repost it. And again, please edit your posts above and add code tags. I don't know how I can ask this in such a way as you'll understand the importance of it, since you keep ignoring this request. My link below tells you how to do this.

  12. #12
    mallowgirl12 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    Sorry am new here, so that's why i don't know how to do this

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

  14. #14
    mallowgirl12 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    am reading it now :)

  15. #15
    mallowgirl12 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    import java.awt.image.*;
    import javax.imageio.*;
    import java.io.File;

    public class SlidingBlockModel
    {
    BufferedImage original_image; // the image to be cut up into blocks
    int numCols; // number of columns in the grid of blocks
    int numRows; // number of rows in the grid of blocks
    int empty_col; // holds the column index of the one empty grid element
    int empty_row; // holds the row index of the one empty grid element
    BufferedImage[][] puzzle; // the two '[][]' allows a 2-D array
    // to be created - each element is an image

    public SlidingBlockModel(int numcols, int numrows, String fname)
    {
    numCols = numcols;
    numRows = numrows;
    String image_filename = fname;

    try
    {
    original_image = ImageIO.read(new File(image_filename));
    System.out.println("image " + image_filename + " loaded in ok." );
    System.out.println("image width is: " + original_image.getWidth() + " image height is: " + original_image.getHeight());
    }
    catch (Exception e)
    {
    System.out.println("Sorry - couldn't load in file " + image_filename);
    }
    }
    private BufferedImage getImageRect(int thisCol, int thisRow)
    {
    // if input is out of range, return "null"
    // otherwise, make and return the Rectangle
    int w = original_image.getWidth()/numCols;
    int h = original_image.getHeight()/numRows;
    int x = thisCol*w;
    int y = thisRow*h;
    return original_image.getSubimage(x,y,w,h);
    }

    public static void main(String[] args)
    {
    SlidingBlockModel myModel; = new SlidingBlockModel(6,6, "foo");

    myModel = new SlidingBlockModel(5, 4, "..\\computer.jpg");

    BufferedImage newImg = myModel.getImageRect(6,6);
    puzzle = new BufferedImage[numCols][numRows];
    puzzle[empty_col][empty_row];
    System.out.println("image width is: " + newImg.getWidth() + " image height is: " + newImg.getHeight());
    }

    }

    C:\Users\123\Documents\Workshop5\Task3\SlidingBloc kModel.java:45: illegal start of expression
    SlidingBlockModel myModel; = new SlidingBlockModel(6,6, "foo");
    ^
    C:\Users\123\Documents\Workshop5\Task3\SlidingBloc kModel.java:51: not a statement
    puzzle[empty_col][empty_row];
    ^
    2 errors

    Tool completed with exit code 1

Posting Permissions

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