Results 1 to 15 of 15
Thread: SlidingBlockModel
- 03-13-2011, 12:02 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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
-
You need to show us more code, I think.
- 03-13-2011, 12:22 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
the full code
the full codeJava 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()); } }Last edited by Fubarable; 03-13-2011 at 12:30 PM.
-
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.
- 03-13-2011, 12:42 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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
-
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?
-
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.
- 03-13-2011, 12:46 PM #8
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
Thanks, so i just need to change something in the code provided?
-
- 03-13-2011, 12:57 PM #10
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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
-
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.
- 03-13-2011, 12:59 PM #12
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
Sorry am new here, so that's why i don't know how to do this
-
Did you read the link? What about it confuses you??
- 03-13-2011, 01:02 PM #14
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
am reading it now :)
- 03-13-2011, 01:22 PM #15
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks