Results 1 to 16 of 16
Thread: IF statement issue
- 03-10-2012, 11:17 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 9
- Rep Power
- 0
IF statement issue
This is probably just a stupid error on my part but I can't figure out where I've gone wrong. When I run this program to test it, it refuses to function beyond the IF statement & and I'm thinking there's something wrong there but I'm not sure.
Although the pictures I use for this are the same size (480x360) and two pictures of the same size is what is required for this to work properly and my code is the exact same as when I did just a morph instead of a movie morph, it will not run properly. Help would be greatly appreciated.
Code was made in DrJava IDE. Please ignore the comments (they are part of the requirement for my assignment)
Java Code:public class MorphingMovie { public static void main(String[] args) { //Use Swan.jpg from mediasources String pic1 = FileChooser.pickAFile(); Picture startPicture = new Picture(); int startWidth = startPicture.getWidth(); int startHeight = startPicture.getHeight(); //Use twoSwans.jpg from media sources String pic2 = FileChooser.pickAFile(); Picture endPicture = new Picture(pic2); int endWidth = endPicture.getWidth(); int endHeight = endPicture.getHeight(); if((startWidth != endWidth) || (startHeight != endHeight)) { SimpleOutput.showInformation("Sorry. The files are not the same size."); } else { int rate = SimpleInput.getIntNumber("Enter Integer Number: "); //Directory name String directoryName = ("C:/Movie1/"); Picture[] pictureArray; pictureArray = new Picture[rate + 2]; pictureArray[0] = startPicture; pictureArray[pictureArray.length - 1] = endPicture; //Morphing pictures for (int i = 1; i < pictureArray.length; i++) { Picture intermediate = new Picture(startWidth, startHeight); intermediate.morphStage(startPicture, endPicture, rate, i); pictureArray[i] = intermediate; } //Make a Frame Sequence FrameSequencer frameSequencer = new FrameSequencer(directoryName); for (int i = 0; i < pictureArray.length; i++) { frameSequencer.addFrame(pictureArray[i]); } //Make Movie 1 (movie of 20 frames) MoviePlayer movie1 = new MoviePlayer(directoryName); movie1.playMovie(rate); } } }Last edited by AndreaRenee; 03-11-2012 at 12:26 AM.
- 03-10-2012, 11:41 PM #2
Re: IF statement issue
Can you explain what the program does?it refuses to function beyond the IF statement
Try adding some println statements to the program to show where it is executing and where it is refusing to go.
Print out the values of the variables that control where the code executes.
- 03-11-2012, 12:00 AM #3
Senior Member
- Join Date
- Aug 2008
- Location
- Stockholm, Sweden
- Posts
- 119
- Rep Power
- 0
Re: IF statement issue
The "error" you provide says the files aren't of the same size, but isn't that exactly what you test for in the if statement?PHP Code:if((startWidth == endWidth) && (startHeight == endHeight)) { SimpleOutput.showInformation("Sorry. The files are not the same size."); }
- 03-11-2012, 12:24 AM #4
Member
- Join Date
- Mar 2012
- Posts
- 9
- Rep Power
- 0
Re: IF statement issue
yes it is but when I run the program WITH two files of the same size, it still comes up saying the files aren't the same size.
the original code wasJava Code:if(startWidth != endWidth || startHeight != endHeight) { SimpleOutput.showInformation("Sorry. The files are not the same size."); }
- 03-11-2012, 12:28 AM #5
Member
- Join Date
- Mar 2012
- Posts
- 9
- Rep Power
- 0
Re: IF statement issue
The program is supposed to take one picture and morph it into another picture and display that morph as a movie. Original format of the code provided.
Java Code:if (startWidth != endWidth || startHeight != endHeight) { //Pictures are same size so is not supposed to go to this SimpleOutput.showInformation("Sorry. These files are not the same size.") } //Supposed to go here when the pictures are the same size & continue to do the morph else....
- 03-11-2012, 12:51 AM #6
Re: IF statement issue
Have you tried printing the values that are being compared to see what they are?it still comes up saying the files aren't the same size.
- 03-11-2012, 01:32 AM #7
Member
- Join Date
- Mar 2012
- Posts
- 9
- Rep Power
- 0
- 03-11-2012, 01:48 AM #8
Re: IF statement issue
If the values are the same where does the execution flow go?
Did you add printlns to show where he code is executing?
Can you post the debug output and the code that is generating the output.
If they are both equal then above statement would be true.Java Code:if((startWidth == endWidth) && (startHeight == endHeight))
And the following would be false
Java Code:if (startWidth != endWidth || startHeight != endHeight)
- 03-11-2012, 01:56 AM #9
Member
- Join Date
- Mar 2012
- Posts
- 9
- Rep Power
- 0
Re: IF statement issue
When I compile the program, it gives no errors. It compiles perfectly fine.
the If statement is to stop the program from running if the pictures are not the same size. so when it says..then the program is supposed to print "Sorry. The files are not the same size" with this codeJava Code:if (startWidth != endWidth || startHeight != endHeight)
When the files ARE the same size, it is supposed to go to the else and continue on initiating the code I originally posted.Java Code:SimpleOutput.showInformation("Sorry. The files are not the same size.")
The problem is that when it gets to the if statement, it gives me the "Sorry. The files are not the same size." even though the files are the same size.
- 03-11-2012, 02:08 AM #10
Re: IF statement issue
Can you post the debug println output and the code that is generating the output.it gives me the "Sorry. The files are not the same size." even though the files are the same size.
-
Re: IF statement issue
You forgot to set startPicture to pic1?
The way you did for the other picture:Java Code:String pic1 = FileChooser.pickAFile(); Picture startPicture = new Picture();
Perhaps that was your problem?Java Code:String pic2 = FileChooser.pickAFile(); Picture endPicture = new Picture(pic2);
- 03-11-2012, 02:13 AM #12
Re: IF statement issue
Then how are the two values for the start and end images the same?
- 03-11-2012, 02:14 AM #13
Member
- Join Date
- Mar 2012
- Posts
- 9
- Rep Power
- 0
Re: IF statement issue
wow.... just wow... that was the problem. Thank you very much!! That was such a dumb mistake!
also, thanks you as well Norm for your help as well. I'm sorry I am so code-blind!
-
Re: IF statement issue
Haha... don't worry we've all had those days.
- 03-11-2012, 02:17 AM #15
Re: IF statement issue
This is very confusing: How could the values be the same when you printed them out????They are both
Obviously you didn't print them out or you would have seen that they were different.
- 03-11-2012, 05:55 AM #16
Similar Threads
-
Regular Expression issue and setName() method issue
By geforce in forum New To JavaReplies: 2Last Post: 01-30-2012, 03:33 AM -
"If statement" issue
By jdm113497 in forum New To JavaReplies: 10Last Post: 04-13-2011, 12:39 AM -
Issue with deployment script when if statement/filter not valid
By pi4r0n in forum New To JavaReplies: 4Last Post: 02-25-2011, 02:28 PM -
issue with update on table and prepared statement
By hacktorious in forum JDBCReplies: 1Last Post: 01-10-2011, 01:44 AM -
Statement or Prepared Statement ?
By paty in forum JDBCReplies: 3Last Post: 08-01-2007, 04:45 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks