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 :
- add(Component c) : adds component to container.
- addActionListenerListener(ActionListener d) : add actionListener for specified component
- setBackground(Color c) : sets the background color of the specified container
- setSize(int a, int b) : sets the size of container to specified dimensions.
- setText(String s) : sets the text of the label to s.
- getText() : returns the text of the label.
Java program to create a simple calculator with basic +, -, /, * using java swing elements.
Note : this program might not run in an online compiler please use an offline IDE.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Simple Calculator using TCP in Java
- Simple Calculator via UDP in Java
- Java Swing | Simple User Registration Form
- Java Swing | Create a simple text editor
- How to build a simple Calculator app using Android Studio?
- Java Swing | Translucent and shaped Window in Java
- Java Swing | JPopupMenu
- Java Swing | JSpinner
- Java Swing | JProgressBar
- Java Swing | JPasswordField
- Java Swing | Look and Feel
- Java Swing | JMenuBar
- Java Swing | JTextArea
- Java Swing | JFileChooser
- Java Swing | JToolBar
- Java Swing | JSlider
- Java Swing | ToolTip
- JRadioButton | Java Swing
- Java Swing | JTable
- Java Swing | JTextField
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.