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.

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30

Thread: GUI Calculator: Adding Answer Button? Please Help

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: GUI Calculator: Adding Answer Button? Please Help

    outside the if statements, it has no value.
    No, the answer variable will have a value anywhere in the method. It will default to zero and then can be changed anywhere by an assignment statement.
    Add printlns to show its value before and after all the if statements where it has a value assigned to it.

  2. #27
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: GUI Calculator: Adding Answer Button? Please Help

    Quote Originally Posted by Norm View Post
    Add printlns to show its value before and after all the if statements where it has a value assigned to it.
    I'm confused right now.. Can you show me an example of how this works?
    Simplicity calls for Complexity. Think about it.

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: GUI Calculator: Adding Answer Button? Please Help

    public void aMethod() {
      int aMethodVar = 0;  // define this variable at the method level
      System.out.println("1aMethodVar=" + aMethodVar);  // show its value here
      if (cond) {
         int x = 0;  // define this variable inside of the if{} it goes away at the ending }
     
         // aMethodVar is known here
        aMethodVar = 234;  // change the value
      } // end of if x is now gone
      System.out.println("2aMethodVar=" + aMethodVar);  // show its value here 
      int anotherVar = 33; // define this variable at the method level
     
      if(cond2) {
         // anotherVar and aMethodVar are known here. x is NOT known
        aMethodVar = 432;  // change the value
      }
    } // end aMethod()
     System.out.println("3aMethodVar=" + aMethodVar);  // show its value here

  4. #29
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: GUI Calculator: Adding Answer Button? Please Help

    I still don't understand how the println's make a difference.. It's fine though, I've moved onto a new project. Here's my completed calculator.

    FinalCalc.JPG

    Thank you for all your help, and patience.
    Simplicity calls for Complexity. Think about it.

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: GUI Calculator: Adding Answer Button? Please Help

    I still don't understand how the println's make a difference
    They don't effect how your code executes.
    The printlns are for debugging. To show you what the values of variables are as the code executes.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: July 20th, 2011, 08:03 AM
  2. need answer for these
    By satishbs in forum Java Theory & Questions
    Replies: 2
    Last Post: April 15th, 2011, 01:46 AM
  3. Adding Radio Button Values
    By bazazu in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 13th, 2010, 10:41 AM
  4. Adding fixed size picture and button to panel
    By Javabeginner in forum AWT / Java Swing
    Replies: 10
    Last Post: August 23rd, 2010, 06:07 PM
  5. [SOLVED] Problem with a tutorial program(Adding the answer of two squared numbers together)
    By Melawe in forum What's Wrong With My Code?
    Replies: 20
    Last Post: April 7th, 2010, 09:03 AM