Swing is a part of the JFC (Java Foundation Classes). Building Graphical User Interface in Java requires the use of Swings. Swing Framework contains a large set of components which allow a high level of customization and provide rich functionalities, and is used to create window-based applications. Java swing components are lightweight, platform-independent, provide powerful components like tables, scroll panels, buttons, list, colour chooser, etc.
In this article, we will see how to write the students information in a Jframe and store it in a file.
Approach: To solve this problem, the following steps are followed:
- First, we need to create a frame using JFrame.
- Next create JLabels, JTextFields, JComboBoxes, JButtons and set their bounds respectively.
- Name these components accordingly and set their bounds.
- Now, in order to save the data into the text file on button click, we need to add Event Handlers. In this case, we will add ActionListener to perform an action method known as actionPerformed in which first we need to get the values from the text fields which is default as a “string”.
- Finally, the Jbuttons, JLabels, JTextFields and JComboBoxes are added to the JFrame and the text is stored in a text file.
Below is the implementation of the above approach:
- The window displayed on running the program:
- Entering the data:
- The dialog box showed after clicking on the save button:
- The text file in which the data is stored:
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Student Information Management System
- Java program to convert Currency using AWT
- Java.awt.image.RescaleOp Class in Java with Examples
- Student Grade Calculator using Java Swing
- Student Record System using Java Swing
- Robot Class in Java AWT
- Java AWT | GridLayout Class
- Java AWT | Cursor class with examples
- Java AWT | Choice Class
- Java AWT | Desktop Class
- Java AWT | Color Class
- Java AWT | MouseInfo and PointerInfo
- Java AWT | Dimension Class
- Java AWT | Canvas Class
- Java AWT | Ellipse2D
- Java AWT | WindowStateListener
- Java AWT | FlowLayout
- Java AWT | BorderLayout Class
- Java AWT | CardLayout Class
- Java AWT | SpringLayout Class
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.