0% found this document useful (0 votes)
55 views28 pages

Ajp Microproject

This document describes a study on Swing and Swing components in Java conducted by three students - Sai R Konda, Gourav V Bhatia, and Nayan V Vishe - under the guidance of Prof. Shweta Chanchlani. It includes certificates certifying the satisfactory completion of the micro project on the topic by each student for their Diploma in Information Technology at Shivajirao S Jondhle Polytechnic in Asangaon, Maharashtra, India. The document also includes an index of topics that will be covered in the study.

Uploaded by

nayan29703
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views28 pages

Ajp Microproject

This document describes a study on Swing and Swing components in Java conducted by three students - Sai R Konda, Gourav V Bhatia, and Nayan V Vishe - under the guidance of Prof. Shweta Chanchlani. It includes certificates certifying the satisfactory completion of the micro project on the topic by each student for their Diploma in Information Technology at Shivajirao S Jondhle Polytechnic in Asangaon, Maharashtra, India. The document also includes an index of topics that will be covered in the study.

Uploaded by

nayan29703
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Program Name : Advanced Java Programming(22517) Academic Year : 2023-24

Course Name : TYIF Semester : Fifth

A STUDY ON
Swing and Swing Components In Java
SUBMITTED ON Nov BY THE GROUP OF 3 STUDENT

Sr. Roll No. Full Name of Students Enrollment Seat No.


No (Sem-V) No. (Sem-V)

1 02 SAI R KONDA 2109350131

2 04 GOURAV V BHATIA 2109350133

3 07 NAYAN V VISHE 2109350139

UNDER THE GUIDANCE OF


Prof . Shweta Chanchlani

In 3 years , Diploma In Engineering Technology Maharashtra State


Board
Maharashtra State
Board of Technical
Education Certificate

This is to certify that Mr. Sai Konda Roll No.02 of Fourth Semester of Diploma
in Information Technology at institute Shivajirao S Jondhle Polytechnic
Asangaon (Code:-0935) has completed the micro project satisfactorily in
subject Advanced Java Programming(22517) for the academic year 2023 to
2024 as prescribed in the curriculum I Scheme.

Place : Asangaon Enrollment No : 2109350131

Date : Seat No :

Subject Teacher Head Of The Department Principle

Shweta Chanchlani Shweta Chanchlani Dr. Sneha Jondhle


Maharashtra State
Board of Technical
Education Certificate

This is to certify that Mr. Gourav Bhatia Roll No.04 of Fourth Semester of
Diploma in Information Technology at institute Shivajirao S Jondhle
Polytechnic Asangaon (Code:-0935) has completed the micro project
satisfactorily in subject Advanced Java Programming(22517) for the academic
year 2023 to 2024 as prescribed in the curriculum I Scheme.

Place : Asangaon Enrollment No : 2109350133

Date : Seat No :

Subject Teacher Head Of The Department Principle

Shweta Chanchlani Shweta Chanchlani Dr. Sneha Jondhle


Maharashtra State
Board of Technical
Education Certificate

This is to certify that Mr. Nayan Vishe Roll No.07 of Fourth Semester of
Diploma in Information Technology at institute Shivajirao S Jondhle
Polytechnic Asangaon (Code:-0935) has completed the micro project
satisfactorily in subject Advanced Java Programming(22517) for the academic
year 2023 to 2024 as prescribed in the curriculum I Scheme.

Place : Asangaon Enrollment No : 2109350139

Date : Seat No :

Subject Teacher Head Of The Department Principle

Shweta Chanchlani Shweta Chanchlani Dr. Sneha Jondhle


INDEX

No Description Page No

1 What is Swing

2 Introduction to Swing

3 Features of Swing

4 Example of Swing

5 Difference between Swing and AWT

6 Advantage

7 Disadvantages

8 Conclusion

9 Introduction to Swing Components in Java

10 Top 13 Components of Swing in Java

11 Conclusion
ABSTRACT

• Swing framework is a part of Java Foundation Classes (JFC). JFC is used to create
window-based applications in a real-time environment. It is built on the top of
the
AWT API. Swing is completely developed by using Java language only.
• Swing mainly works on the principle of MVC (Model View Controller).
• The model gives the state of information about the components of swing like
JButton, JPassword Field, JLabel, JTextField, etc. Example: In the case of a combo
box the model consisting a field that determines if the box is multi-selected or
single selected or not selected from the drop-down list. A view shows how the
component or container is displayed on the screen.
• The controller tells you how the specified component reacts to the
user. Example: If there is a frame consists of a username, password, labels, etc.
with the login button as in the below swing example. Once we click on the login
button where the user has to go decides(means where the next action has to go)
by this controller.
Introduction to Swing

Swing is the collection of user interface components for Java programs. It is part of Java
Foundation classes that are referred to as JFC. In simple words, Swing is the graphical
user interface toolkit that is used for developing windows based java applications or
programs. It is the successor of AWT, known as the Abstract window toolkit API for
Java,and AWT components are mainly heavyweight.
The components are lightweight as compared to AWT components. It provides an
excellent interface to the user for all the platforms. It is not specifically for one platform.
The components are written in Java and platform-independent as well. The Java
foundation classes first appeared in 1997, then later called Swing. To use the swing in

java, javax. A swing package needs to be used or imported. It is also known as Java
Swing

Features of Swing
The features of the Swing are as follows:
1. Platform Independent: It is platform-independent; the swing components used
to build the program are not platform-specific. It can be used on any platform
and anywhere.
2. Lightweight: Swing components are lightweight, which helps in creating the UI
lighter. The swings component allows it to plug into the operating system user
interface framework, including the mappings for screens or devices and other
user interactions like keypress and mouse movements.
3. Plugging: It has a powerful component that can be extended to provide support
for the user interface that helps in a good look and feel to the application. It
refers to the highly modular-based architecture that allows it to plug into other
customized implementations and frameworks for user interfaces. Its components
are imported through a package called java.swing.
4. Manageable: It is easy to manage and configure. Its mechanism and composition
pattern also allows changing the settings at run time. The uniform changes can
be provided o the user interface without any changes to the application code.

5. MVC: They mainly follow the concept of MVC, which is the Model View

Controller. With the help of this, we can make changes in one component
without impacting or touching other components. It is known as loosely coupled
architecture as well.

6. Customizable: Swing controls can be easily customized. It can be changed, and the
visual appearance of the component application is independent of its internal
representation.

Examples of Swing,
The component class is mainly used, and some of the methods are frequently used, like
adding a component in another component (add (Component a)) and setting the size,
layout, and visibility of components accordingly.
Below is the example:

importjavax.swing.*;
publicclassTestextendsJFrame{
publicTest(){
super("Test");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
add(newJLabel("Test, Application!"));
pack();
setVisible(true);
}
publicstaticvoidmain(final String[]args){
newTest();
}
}

Other examples to show the button:

importjavax.swing.*;
publicclassSwing{ publicstaticvoidmain
(String[]args){
JFrame f=newJFrame();//creating instance of JFrame
JButton b=newJButton("Submit Button");//creating instance of JButton
b.setBounds(120,90,90,35);//x axis, y axis, width, height
f.add(b);//adding button in JFrame
f.setSize(400,500);//400 width and 500 height
f.setLayout(null);//using no layout managers
f.setVisible(true);//making the frame visible }
}
Difference between Swing and AWT

The difference between Swing and AWT are as follow:

Basic SWING AWT


Comparison

Architecture It follows the model view It doesn’t follow the model-view


controller architecture. architecture.

UI It does support a Pluggable look It doesn’t support a pluggable look


and feel for UI and feel

Components It has a lot of components to It has fewer components


provide for UI. ascompared to Swing.

Independent It is platform Independent. It is platform-dependent.

Weight Its components are lightweight. Its components are heavyweight.

Speed If components are more used, it Its speed would be normal


can be slow. ifcomponents were used
more.
Advantages
The advantages are as follows:
1. The java swing mainly provides built-in double buffering.
2. The new components are built-in swing, providing the support for debugging.
3. Swing components mainly change their appearance, the looks, and the feels of
the UI based on the package being used.
4. It mainly consumes fewer resources than AWT, which is why it is referred to as
Lightweight.

5. It provides other components like icons, decorative borders, tooltips, etc.


6. It mainly provides flexible UI because of following the concept of MVC design
patterns.
7. It provides additional functionality and other components to replace AWT
components.
Disadvantages
The disadvantages are as follows:
1. The components need version Java 1.2 and other separate jar files to consume.
2. It can be slower than AWT.
3. To develop the application in swing, the individual has to be very careful with
programming.
4. Sometimes, the components have not appeared as they
should. 8.
Swing components are the basic building blocks of an application. We know that Swing isa
GUI widget toolkit for Java. Every application has some basic interactive interface for the
user. For example, a button, checkbox, radio-button, text-field, etc. These together form
the components in Swing.
So, to summarize, Swing components are the interactive elements in a Java application.
We will see various Swing Components in this article and see a few examples. Note that
the examples are simple code snippets. You can use them in your application and tailor
them to suit your application architecture.
Top 13 Components of Swing in Java
Below are the different components of swing in java

 ImageIcon.
 JButton.
 JLabel. ...
 JTextField. ...
 JTextArea. ...
 JPasswordField. ...
 JCheckBox. ...
 JRadioButton.
 JList
 JcomboBox
 JfileChooser
 JTabbedPane
 JSlider
ImageIcon
The ImageIcon component creates an icon sized-image from an image residing at the
source URL.
Example:

ImageIconhomeIcon =newImageIcon("src/images/home.jpg");

This returns an icon of a home button. The string parameter is the path at which the
source image is present.
Note: We would be using this image icon in further examples.

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.
Example:

JButtonokBtn =newJButton("Ok");

This constructor returns a button with text Ok on it.

JButtonhomeBtn =newJButton(homeIcon);

It returns a button with a homeIcon on it.

JButton btn2 =newJButton(homeIcon,"Home");

It returns a button with the home icon and text Home.

2. JLabel
JLabel class is used to render a read-only text label or images on the UI. It does not
generate any event.
Example:

JLabeltextLbl =newJLabel("This is a text label.");

This constructor returns a label with text.

JLabelimgLabel =newJLabel(homeIcon);

It returns a label with a home icon.

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. This parameter sets the width of the box measured by the number of
columns. It does not limit the number of characters that can be input in the box.
Example:
JTextFieldtxtBox =newJTextField(20);

It renders a text box of 20 column width.

4. JTextArea
JTextArea class renders a multi-line text box. Similar to the JTextField, a user can input
non-formatted text in the field. The constructor for JTextArea also expects two integer
parameters which define the height and width of the text-area in columns. It does not
restrict the number of characters that the user can input in the text-area.

Example:

JTextAreatxtArea =newJTextArea("This text is default text for text area.",5,20);


The above code renders a multi-line text-area of height 5 rows and width 20 columns,
with default text initialized in the text-area.

5. JPasswordField
JPasswordField is a subclass of JTextField class. It renders a text-box that masks the user
input text with bullet points. This is used for inserting passwords into the application.
Example:
JPasswordFieldpwdField =newJPasswordField(15);

var pwdValue=pwdField.getPassword();

It returns a password field of 15 column width. The getPassword method gets the value
entered by the user.

6. 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.
Example:

CheckBoxchkBox =newJCheckBox("Show Help",true);

It returns a checkbox with the label Show Help. Notice the second parameter in the
constructor. It is a boolean value that indicates the default state of the check-box. True
means the check-box is defaulted to on state.

7. JRadioButton
JRadioButton is used to render a group of radio buttons in the UI. A user can select one
choice from the group.
Example:
ButtonGroupradioGroup =newButtonGroup(); JRadioButton rb1 =newJRadioButton("Easy",true); JRadio
radioGroup .add(rb2);

radioGroup .add(rb3);

The above code creates a button group and three radio button elements. All three
elements are then added to the group. This ensures that only one option out of the
available options in the group can be selected at a time. The default selected option is
set to Easy.

8. JList
JList component renders a scrollable list of elements. A user can select a value ormultiple
values from the list. This select behavior is defined in the code by the developer.
Example:
DefaultListItemcityList =newDefaultListItem(); cityList .addElement("Mumbai"):
cityList .addElement("London"): cityList .addElement("New York"):
cityList .addElement("Sydney"):
cityList .addElement("Tokyo"):

JList cities =newJList(cityList);

The above code renders a list of cities with 5 items in the list. The selection restriction is
set to SINGLE_SELECTION. If multiple selections is to be allowed, set the behavior to
MULTIPLE_INTERVAL_SELECTION.

9. JComboBox
JComboBox class is used to render a dropdown of the list of options.
Example:
String []cityStrings={"Mumbai","London","New York","Sydney","Tokyo"};

JComboBox cities =newJComboBox(cityList);

cities .setSelectedIndex(3);

The default selected option can be specified through the setSelectedIndex method. The
above code sets Sydney as the default selected option.

10. JFileChooser
JFileChooser class renders a file selection utility. This component lets a user select a file
from the local system.
Example:
JFileChooserfileChooser =newJFileChooser(); JButtonfileDialogBtn =newJButton("Select File"); fileDialog
})
var selectedFile=fileChooser.getSelectedFile();

The above code creates a file chooser dialog and attaches it to the button. The button
click would open the file chooser dialog. The selected file is returned through the
getSelectedFile method.

11. JTabbedPane
JTabbedPane is another very useful component that lets the user switch between tabs
in an application. This is a highly useful utility as it lets the user browse more content
without navigating to different pages.
Example:
JTabbedPanetabbedPane =newJTabbedPane();
tabbedPane .addTab("Tab 1",newJPanel()); tabbedPane .addTab("Tab 2",newJPanel());

The above code creates a two tabbed panel with headings Tab 1 and Tab 2.

12. JSlider
JSlider component displays a slider which the user can drag to change its value. The
constructor takes three arguments – minimum value, maximum value, and initial value.
Example:
JSlidervolumeSlider =newJSlider(0,100,50); var volumeLevel=volumeSlider.getValue();

The above code creates a slider from 0 to 100 with an initial value set to 50. The value
selected by the user is returned by the getValue method.
CONCLUSION

It is the framework 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 package or library to perform and define the look and feel of the
project or application.
It is referred to as the next-generation GUI developed for Java programs. Java Swing is a
library of the GUI controls, and classes are not platformed dependent and are lighter in
weight because they don’t create the peer components. It mainly provides a consistent
appearance or the look and feel of the application across all the platforms.

Now that you have got the gist of components in Swing, it is highly recommended to
dive deeper and explore more. Swing components are fun to play around with and can
help create some real cool applications. So, get your hands-on on these components by
including them in your Swing application.
Introduction to Swing Components in Java

You might also like