Search:

Type: Posts; User: Norm

Search: Search took 0.17 seconds.

  1. Re: GUI Calculator: Adding Answer Button? Please Help

    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.
  2. 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;...
  3. Re: GUI Calculator: Adding Answer Button? Please Help

    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...
  4. Re: GUI Calculator: Adding Answer Button? Please Help

    This doesn't make any sense to me. The variable answer is a method level variable.
    I have no idea what you mean by "is bound to". Can you explain?

    Your simple example seems to have another...
  5. Re: GUI Calculator: Adding Answer Button? Please Help

    If the variable only needs to be known in the method with the if statements, define the variable at the method level: inside of the {}s that hold the method's statements and not inside of an {}s...
  6. Re: GUI Calculator: Adding Answer Button? Please Help

    Same type of problem dealing with the scope of a variable. You need to define the variable at a level that the code in both if statements can see it.
  7. Re: GUI Calculator: Adding Answer Button? Please Help

    You need to move ALL of the component definitions OUT of the main method to the class level.
    Nothing that you define in a method will be known outside of the method.
    Defining a variable is not the...
  8. Re: GUI Calculator: Adding Answer Button? Please Help

    That sounds like an error message from a compiler.
  9. Re: GUI Calculator: Adding Answer Button? Please Help

    As you gain experience you'll be able to create new classes as needed.
  10. Re: GUI Calculator: Adding Answer Button? Please Help

    Passing a value to a method or constructor:

    objRef.method(answer); // pass answer to the method

    AClass aClass = new AClass(answer); // pass answer to the constructor

    Example of the...
  11. Re: GUI Calculator: Adding Answer Button? Please Help

    Not a method, a new listener class.
    You will need a reference to the answer variable if you want to use its value.
    If answer is a class reference you can pass it to the constructor for the...
  12. Re: GUI Calculator: Adding Answer Button? Please Help

    Add an action listener to the Answer button. In that listener's actionPerformed method, do what you want done when the button is pressed.


    What is done in that listener? Why not set the text...
Results 1 to 12 of 12