Results 1 to 16 of 16
Like Tree1Likes
  • 1 Post By Norm

Thread: IF statement issue

  1. #1
    AndreaRenee is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default 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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default Re: IF statement issue

    it refuses to function beyond the IF statement
    Can you explain what the program does?
    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.

  3. #3
    ojn
    ojn is offline Senior Member
    Join Date
    Aug 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default Re: IF statement issue

    PHP Code:
    if((startWidth == endWidth) && (startHeight == endHeight))
        {
          SimpleOutput.showInformation("Sorry. The files are not the same size.");
        }
    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?

  4. #4
    AndreaRenee is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default Re: IF statement issue

    Quote Originally Posted by ojn View Post
    PHP Code:
    if((startWidth == endWidth) && (startHeight == endHeight))
        {
          SimpleOutput.showInformation("Sorry. The files are not the same size.");
        }
    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?
    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 was
    Java Code:
     if(startWidth != endWidth || startHeight != endHeight)
    {
    SimpleOutput.showInformation("Sorry. The files are not the same size.");
    }

  5. #5
    AndreaRenee is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default 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....

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default Re: IF statement issue

    it still comes up saying the files aren't the same size.
    Have you tried printing the values that are being compared to see what they are?

  7. #7
    AndreaRenee is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default Re: IF statement issue

    Quote Originally Posted by Norm View Post
    Have you tried printing the values that are being compared to see what they are?
    Yes I have and I just double checked them to make sure my eyes didn't play any tricks on me. They are both 480(width) by 360(height)

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default 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.

    Java Code:
    if((startWidth == endWidth) && (startHeight == endHeight))
    If they are both equal then above statement would be true.
    And the following would be false
    Java Code:
    if (startWidth != endWidth || startHeight != endHeight)

  9. #9
    AndreaRenee is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default 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..
    Java Code:
     if (startWidth != endWidth || startHeight != endHeight)
    then the program is supposed to print "Sorry. The files are not the same size" with this code
    Java Code:
     SimpleOutput.showInformation("Sorry. The files are not the same size.")
    When the files ARE the same size, it is supposed to go to the else and continue on initiating the code I originally posted.

    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.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default Re: IF statement issue

    it gives me the "Sorry. The files are not the same size." even though the files are the same size.
    Can you post the debug println output and the code that is generating the output.

  11. #11
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: IF statement issue

    You forgot to set startPicture to pic1?

    Java Code:
        String pic1 = FileChooser.pickAFile();
        Picture startPicture = new Picture();
    The way you did for the other picture:

    Java Code:
        String pic2 = FileChooser.pickAFile();
        Picture endPicture = new Picture(pic2);
    Perhaps that was your problem?

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default Re: IF statement issue

    Then how are the two values for the start and end images the same?

  13. #13
    AndreaRenee is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default 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!

  14. #14
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: IF statement issue

    Haha... don't worry we've all had those days.

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default Re: IF statement issue

    They are both
    This is very confusing: How could the values be the same when you printed them out????
    Obviously you didn't print them out or you would have seen that they were different.
    DarrylBurke likes this.

  16. #16
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: IF statement issue

    I agree with Norm. Neglecting advice and posting misinformation isn't going to help you.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Regular Expression issue and setName() method issue
    By geforce in forum New To Java
    Replies: 2
    Last Post: 01-30-2012, 03:33 AM
  2. "If statement" issue
    By jdm113497 in forum New To Java
    Replies: 10
    Last Post: 04-13-2011, 12:39 AM
  3. Replies: 4
    Last Post: 02-25-2011, 02:28 PM
  4. Replies: 1
    Last Post: 01-10-2011, 01:44 AM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 PM

Tags for this Thread

Posting Permissions

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