38 Hardikparmar Exp13
38 Hardikparmar Exp13
Date of 02/12/21
Performance:
Date of 12/12/21
Submission:
Program formation/
Execution/ Documentatio Timely B Viva Experiment Teacher Signature
ethical n Submission answers Marks (15) with date
practices (07) (02) (03) (03)
Experiment No.13
Aim:- Study of Swing.
Lab Outcome:- 2.ITL304.5 Design and develop Graphical User Interface using
Abstract Window Toolkit and Swings along with response to the events.
Problem Statement:-
Write a Java program to implement Swing components namely Buttons,
JLabels, Checkboxes, Radio Buttons, JScrollPane, JList, JComboBox, Trees,
Tables Scroll pan Menus and Toolbars to design interactive GUI.
Theory:-
Java Swing tutorial is a part of Java Foundation Classes (JFC) that is used to
create window-based applications. It is built on the top of AWT (Abstract
Windowing Toolkit) API and entirely written in java.
1. JButton: JButton class is used to create a push-button on the UI. The
button can contain some display text or image. It generates an event when
clicked and double-clicked. A JButton can be implemented in the application by
calling one of its constructors.
2. JLabel: JLabel class is used to render a read-only text label or images on
the UI. It does not generate any event.
3. JTextField: JTextField renders an editable single-line text box. A user can
input non-formatted text in the box. To initialize the text field, call its
constructor and pass an optional integer parameter to it.
4. JCheckBox: JCheckBox renders a check-box with a label. The check-box
has two states – on/off. When selected, the state is on and a small tick is
displayed in the box.
5. JRadioButton: JRadioButton is used to render a group of radio buttons in
the UI. A user can select one choice from the group.
6. JList: JList component renders a scrollable list of elements. A user can
select a value or multiple values from the list. This select behavior is defined in
the code by the developer.
7. JComboBox: JComboBox class is used to render a dropdown of the list of
options.
8. JScrollPane: Creates an empty scroll pane (no viewPort). It can have
both vertical and horizontal scrollbars when needed.
9. JTable: In Java, Swing toolkit contains a JTable Class. It is under package
javax.swing.JTable class. It used to draw a table to display data.
10. JFrame: JFrame descends from the Frame class. The components added
to the Frame are called contents of the Frame.
11. JTree: The JTree class is used to display the tree structured data or
hierarchical data. JTree is a complex component. It has a 'root node' at the top
most which is a parent for all nodes in the tree. It inherits JComponent class.
12. JToolBar: JToolBar container allows us to group other components,
usually buttons with icons in a row or column. JToolBar provides a component
which is useful for displaying commonly used actions or controls.
13. Program:- import javax.swing.*; import java.awt.*; import
java.awt.event.*;
c = getContentPane();
c.setLayout(null);
dob.setLocation(100, 250);
c.add(dob);
c.add(reset);
Conclusion:-
It is the framework that is used for building windows based applications for
Java. It was developed to solve the issues that are in AWT. It provides more
components to work and uses extensible components to develop the
applications. There are many components in the swing package or library to
perform and define the look and feel of the project or application.