Science, Tech, Math › Computer Science A Calculator Example Program (With Java Code) Share Flipboard Email Print Images Etc Ltd / Getty Images Computer Science Java Programming PHP Programming Perl Python Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Paul Leahy Computer Science Expert M.A., Advanced Information Systems, University of Glasgow Paul Leahy is a computer programmer with over a decade of experience working in the IT industry, as both an in-house and vendor-based developer. our editorial process Paul Leahy Updated July 03, 2019 The following Java code is for a simple calculator. There are nine JButtons to represent the numbers 1 to 9, and three JButtons for addition, subtraction and totaling the result. A JTextField at the top keeps track of the numbers being pressed and the result of the arithmetic operation. Java Code The purpose of this Java program is to show how to implement an ActionListener interface for handling JButton button event clicks by using the containing class, an inner class, and an anonymous inner class. Cite this Article Format mla apa chicago Your Citation Leahy, Paul. "A Calculator Example Program (With Java Code)." ThoughtCo, Aug. 27, 2020, thoughtco.com/calculator-example-program-with-java-4163459. Leahy, Paul. (2020, August 27). A Calculator Example Program (With Java Code). Retrieved from https://www.thoughtco.com/calculator-example-program-with-java-4163459 Leahy, Paul. "A Calculator Example Program (With Java Code)." ThoughtCo. https://www.thoughtco.com/calculator-example-program-with-java-4163459 (accessed January 23, 2021). copy citation