VOOZH about

URL: https://www.geeksforgeeks.org/java/java-swing-simple-calculator/

⇱ Java Swing | Simple Calculator - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Swing | Simple Calculator

Last Updated : 16 Apr, 2021

Java Swing is a GUI (graphical user Interface) widget toolkit for Java. Java Swing is a part of Oracle's Java foundation classes . Java Swing is an API for providing graphical user interface elements to Java Programs.Swing was created to provide more powerful and flexible components than Java AWT (Abstract Window Toolkit).
In this article we will use Java Swing components to create a simple calculator with only +, -, /, * operations.
methods used : 
 

  1. add(Component c) : adds component to container.
  2. addActionListenerListener(ActionListener d) : add actionListener for specified component
  3. setBackground(Color c) : sets the background color of the specified container
  4. setSize(int a, int b) : sets the size of container to specified dimensions.
  5. setText(String s) : sets the text of the label to s.
  6. getText() : returns the text of the label.


Java program to create a simple calculator with basic +, -, /, * using java swing elements. 
 

Output : 
 

👁 Image


 


Note : this program might not run in an online compiler please use an offline IDE.
 

Comment
Article Tags:
Article Tags: