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.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java GUI Calculater

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Thanked 0 Times in 0 Posts

    Default Java GUI Calculater

    Hey this is my first post, I need some help with making a GUI Calculator, this is a extract from the code, I make the variables "num1" and "operator" in the PlusAction but when I try use them in the EqualsAction it doesn't reconise them and cant find them, PLEASE HELP

    private void jBtnPlusActionPerformed(java.awt.event.ActionEvent evt) {

    double num1 = Double.parseDouble (this.jTxtInput.getText());
    String operator = "+";


    private void jBtnEqualsActionPerformed(java.awt.event.ActionEve nt evt) {
    Double num2 = Double.parseDouble(this.jTxtInput.getText());
    Double ans=0.0;
    { ans = num1 + num2;

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 634 Times in 540 Posts

    Default Re: Java GUI Calculater

    What you've just described is the appropriate behavior. If you create a variable inside a block, like an if statement or an actionPerformed() method, that variable won't be visible outside of that method.

    You might have to rethink your design a bit, or at least when you declare those variables.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 2
    Last Post: January 18th, 2013, 10:12 AM
  2. Need help with creating simple calculater
    By YourCrazyFriend in forum Java Theory & Questions
    Replies: 15
    Last Post: March 2nd, 2012, 09:19 AM
  3. New to java trying a GUI
    By dj56 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 2nd, 2011, 09:26 AM

Tags for this Thread