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 10 of 10

Thread: please tell me why this code does not work

  1. #1
    Member
    Join Date
    Nov 2010
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default please tell me why this code does not work

    this is the main
    when compiling i got this:
    --------------------Configuration: <Default>--------------------
    D:\javafiles\Image Matching\ImageMatching.java:34: '.class' expected
    mf_pixTrillice=mf.createPixels(int mf_getrows, int mf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:34: ';' expected
    mf_pixTrillice=mf.createPixels(int mf_getrows, int mf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:34: ';' expected
    mf_pixTrillice=mf.createPixels(int mf_getrows, int mf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:35: '.class' expected
    sf_pixTrillice=sf.createPixels(int sf_getrows, int sf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:35: ';' expected
    sf_pixTrillice=sf.createPixels(int sf_getrows, int sf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:35: ';' expected
    sf_pixTrillice=sf.createPixels(int sf_getrows, int sf_getcols);
    ^
    6 errors

    Process completed.

     
    import java.util.*;
     
    public class ImageMatching
    {
    	public static void main (String[] args) 
    		{
     
    		Scanner readDim=new Scanner(System.in);
     
    		MainFrame mf = new MainFrame();
    		SubFrame sf  = new SubFrame ();
     
    		Random rand = new Random();
    		int mf_getrows, mf_getcols, sf_getrows, sf_getcols;
    		int [][] mf_pixTrillice ;
    		int [][] sf_pixTrillice ;
    		int [][][] coRel;
     
    		       System.out.println("size of the main window:");
    		       System.out.print("Horizontal Magnitude =");
    		                  mf_getrows=readDim.nextInt();
    		       System.out.print("Vertical Magnitude =");
    		                  mf_getcols=readDim.nextInt();
    		                  mf.setSize(mf_getrows, mf_getcols);// assign to mf_horz mag and vert mag
     
    		       System.out.print("size of the Sub window:");
    		       System.out.print("\nHorizontal Magnitude =");
    		                  sf_getrows=readDim.nextInt();
    		       System.out.print("Vertical Magnitude =");
    		                  sf_getcols=readDim.nextInt();		              
    		                  sf.setSize(sf_getrows, sf_getcols);// assign to sf_horz mag and vert mag
     
    		mf.defineValidWindows(mf_getrows,mf_getcols,sf_getrows,sf_getcols);//if sf coor > mf coor-> reverse; else set/assign
    		mf_pixTrillice=mf.createPixels(int mf_getrows, int mf_getcols);
    		sf_pixTrillice=sf.createPixels(int sf_getrows, int sf_getcols);
     
    		         for(int i=0; i<mf_pixTrillice.length; i++)
    		         {
    		         	for (int j=0; j<mf_getcols; j++)
    		         	{
    		         		int value=(int) (10*rand.nextInt()); // assigning random values to the pixels
    		         		     if (value < 0)
    		         		         mf_pixTrillice[i][j]=value*(-1);
    		         		             else
    		         		                  mf_pixTrillice[i][j]=value; 
    		         		     System.out.print(mf_pixTrillice[i][j]);
    		         		     System.out.print("  ");
    		         	}
    		         	System.out.print("\n");	
    		         }		
     
    		         	System.out.print("\n\n");	
     
    		         for(int i=0; i<sf_pixTrillice.length; i++)
    		         {
    		           	for (int j=0; j<sf_getcols; j++)
    		         	{
    		         		int value=(int) (10*rand.nextInt()); // assigning random values to the pixels
    		         		if (value < 0)
    		         			sf_pixTrillice[i][j]=value*(-1);
    		         		        else
    		         		   	         sf_pixTrillice[i][j]=value; 
    		         		System.out.print(sf_pixTrillice[i][j]);
    		         		System.out.print("  ");
    		         	}
    		         	System.out.print("\n");
    		         }
     
     }
    }
     
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    public class MainFrame
    {
    	   public  int OrgPnt1_X;
    	   public  int OrgPnt1_Y;
    	   public  int OrgPnt2_X;
    	   public  int OrgPnt2_Y;
    	   int returnCols;
    	   public  int H_Magnitude;
    	   public  int V_Magnitude;
     
    	public void setSize(int dim1, int dim2)
    	{
    		H_Magnitude=dim1;
    		V_Magnitude=dim2;
    		OrgPnt1_X=H_Magnitude;
    		OrgPnt1_Y=V_Magnitude;		
    	}
    	public static int [][] createPixels(int row, int col)
    	{
    	    returnCols = col;
    		int [][] Pixels=new int [row][col];
    		         return Pixels;
    	}
    	public int getColsNum()
    	{
    		return returnCols;
    	}
    	public  void defineValidWindows(int pnt1x, int pnt1y,int pnt2x, int pnt2y) // this method belongs for both super and sub classs
    	{ 
    		    int sf_OrgPnt2_X=pnt2x; 
    		    int sf_OrgPnt2_Y=pnt2y;
    		    int	mf_OrgPnt1_X=pnt1x;
    		    int	mf_OrgPnt1_Y=pnt1y;
    		    int temp=0; // in java a variable MUST be initialized 
     
    		if ( (mf_OrgPnt1_X < sf_OrgPnt2_X) || (mf_OrgPnt1_Y < sf_OrgPnt2_Y ) )
    		{
    			if (mf_OrgPnt1_X < sf_OrgPnt2_X)
    			{
    			        temp=mf_OrgPnt1_X;
    			        mf_OrgPnt1_X=sf_OrgPnt2_X;
    			        sf_OrgPnt2_X=temp;
     
    			        OrgPnt1_X=mf_OrgPnt1_X;
    			        OrgPnt2_X=sf_OrgPnt2_X;
    			}
    			if (mf_OrgPnt1_Y < sf_OrgPnt2_Y)
    			{
    			        temp=mf_OrgPnt1_Y;
    			        mf_OrgPnt1_Y=sf_OrgPnt2_Y;
    			        sf_OrgPnt2_Y=temp;     
     
    				    OrgPnt1_Y=mf_OrgPnt1_Y;
    				    OrgPnt2_Y=sf_OrgPnt2_Y;
    			}
     
    		}
            if ((mf_OrgPnt1_X==sf_OrgPnt2_X) || (mf_OrgPnt1_Y==sf_OrgPnt2_Y) )  
            {
            	 if ( sf_OrgPnt2_X==mf_OrgPnt1_X )
            	 {
            	  	 sf_OrgPnt2_X=mf_OrgPnt1_X - 1;
            	 	 OrgPnt2_X=sf_OrgPnt2_X;
            	 }
            	 	   if ( sf_OrgPnt2_Y==mf_OrgPnt1_Y )
            	 	   {
            	 	   	   sf_OrgPnt2_Y=mf_OrgPnt1_Y-1;       	
            	 	   	   OrgPnt2_Y=sf_OrgPnt2_Y;
            	 	   }
            }
         }//end of the method
    }// end of the class	
     
     
    class SubFrame extends MainFrame
    {
    /*	SubFrame(int horz_dim, int vert_dim)
    	{
    		super(horz_dim,vert_dim);
    	} */
    }// end of the class
    Last edited by amr; December 6th, 2010 at 05:25 PM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: please tell me why this code does not work

    You have to give us some information on what the problem is. I really doubt anyone is going to bother to compile the code or anything for you to see what is happening.

    What is happening that shouldn't be happening? What do you expect to happen?

    Providing help is a two-way street. The quality of the help you receive depends on the quality of the information you provide.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: please tell me why this code does not work

    Well, you don't have constructors for your two classes,

    MainFrame and Subframe.

    That might be part of the problem.

  4. #4
    Member
    Join Date
    Nov 2010
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: please tell me why this code does not work

    Quote Originally Posted by javapenguin View Post
    Well, you don't have constructors for your two classes,

    MainFrame and Subframe.

    That might be part of the problem.

    thanks for replying.
    should i make constructors????

  5. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: please tell me why this code does not work

    Yes.

    Also, I think it'd be best if your two classes

    MainFrame and SubFrame were in separate java files from the main one, and from each other.

    Also, you don't have a constructor in MainFrame that matches the parameters you plan to call super with in Subframe.

    You need both that constructor, and a no-parameter constructor for MainFrame if you plan to do that.

    (Why you need the no-parameter constructor I'm not quite 100% sure, but it's required to have a default(or no-parameter) constructor if you're going to extend that class.)

    Also, it appears, unless you change so things, you'll need a default constructor for Subframe as well as the one you plan to make, this time only because you're calling a default constructor to initialize it in your main class.

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: please tell me why this code does not work

    Quote Originally Posted by amr View Post
    thanks for replying.
    should i make constructors????
    Javapenguin is not correct here...constructors are not your problem and no, you do not have to make constructors unless you wish to pass variables in order to create the class - which you don't. Your problems are basic syntax errors. First

    sf_pixTrillice=sf.createPixels(int sf_getrows, int sf_getcols);

    Do not add the variable type when passing arguments to a method. Remove the int's in your method calls.
    Second, you try and access the variable returnCols (which is not static) from a static method. This needs to be somehow rectified by making it static, or dealing with it in another way.

  7. #7
    Member
    Join Date
    Nov 2010
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: please tell me why this code does not work

    Quote Originally Posted by javapenguin View Post
    Yes.

    Also, I think it'd be best if your two classes

    MainFrame and SubFrame were in separate java files from the main one, and from each other.

    Also, you don't have a constructor in MainFrame that matches the parameters you plan to call super with in Subframe.

    You need both that constructor, and a no-parameter constructor for MainFrame if you plan to do that.

    (Why you need the no-parameter constructor I'm not quite 100% sure, but it's required to have a default(or no-parameter) constructor if you're going to extend that class.)

    Also, it appears, unless you change so things, you'll need a default constructor for Subframe as well as the one you plan to make, this time only because you're calling a default constructor to initialize it in your main class.
    thank you..
    but the problem now,, is, when sending parameter to the method createPixels(int , int )
    i receive error

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: please tell me why this code does not work

    Quote Originally Posted by amr View Post
    i receive error
    What error? Please fully describe the errors otherwise we can only guess.

  9. #9
    Member
    Join Date
    Nov 2010
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: please tell me why this code does not work

    Quote Originally Posted by copeg View Post
    What error? Please fully describe the errors otherwise we can only guess.
    1-java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Process completed.

    2---------------------Configuration: <Default>--------------------
    D:\javafiles\Image Matching\ImageMatching.java:34: '.class' expected
    mf_pixTrillice=mf.createPixels(int mf_getrows, int mf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:34: ';' expected
    mf_pixTrillice=mf.createPixels(int mf_getrows, int mf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:34: ';' expected
    mf_pixTrillice=mf.createPixels(int mf_getrows, int mf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:35: '.class' expected
    sf_pixTrillice=sf.createPixels(int sf_getrows, int sf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:35: ';' expected
    sf_pixTrillice=sf.createPixels(int sf_getrows, int sf_getcols);
    ^
    D:\javafiles\Image Matching\ImageMatching.java:35: ';' expected
    sf_pixTrillice=sf.createPixels(int sf_getrows, int sf_getcols);
    ^
    6 errors

    Process completed.

  10. #10
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: please tell me why this code does not work

    You probably are missing a bracket somewhere.

Similar Threads

  1. [SOLVED] Can't get JFreeChart to work
    By igniteflow in forum Java SE APIs
    Replies: 2
    Last Post: February 15th, 2011, 02:19 AM
  2. home work ..
    By shane1987 in forum Collections and Generics
    Replies: 8
    Last Post: November 16th, 2010, 09:45 AM
  3. [SOLVED] "possible loss of precision", except not, code doesn't work, simple question
    By Perd1t1on in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2010, 07:11 PM
  4. my run program does not work
    By rman27bn in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 16th, 2009, 09:13 AM
  5. Why won't this while loop work?
    By trueblue in forum Loops & Control Statements
    Replies: 2
    Last Post: July 17th, 2009, 09:10 AM