I'm working on this task for my university, and I've come up to an impass.
Im trying to display in a system.out.println method to display the width and height of an image.
So far i've gotten it to load the image correctly, but whenever I put in the code to display the width and height (Using the getWidth and getHeight methods) the compiler tells me that it "Cannot find symbol" even when I declare the getWidth and getHeight in the code, I have no idea why this is, can anyone help me.
import java.awt.image.*; import javax.imageio.*; import java.io.File; 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 static void main(String[] args) { SlidingBlockModel myModel; myModel = new SlidingBlockModel(5, 4, "Horseman-War.jpg"); } SlidingBlockModel(int nc, int nr, String image_filename ) { numCols = nc; numRows = nr; original_image = null; try { original_image = ImageIO.read(new File(image_filename)); System.out.println("image " + image_filename + " loaded in ok."); } catch (Exception e) { System.out.println("Sorry - couldn't load in file " + image_filename); } System.out.println("Width of the window " +w); System.out.println("Height of the window " +h); } }
Here is the error message:
C:\Users\Vesper\Desktop\Practical Programming - CI2250\Workshop 5\Task 2\SlidingBlockModel.java:48: cannot find symbol
symbol : variable w
location: class SlidingBlockModel
System.out.println("Width of the window " +w);
^
C:\Users\Vesper\Desktop\Practical Programming - CI2250\Workshop 5\Task 2\SlidingBlockModel.java:49: cannot find symbol
symbol : variable h
location: class SlidingBlockModel
System.out.println("Height of the window " +h);
^
2 errors
Tool completed with exit code 1