0% found this document useful (0 votes)
42 views10 pages

SWING

Java Swing is a GUI widget toolkit for Java that is built on top of the Abstract Window Toolkit (AWT) and provides a more sophisticated set of GUI components that are platform independent, lightweight, and follow the model-view-controller framework. Key classes for building graphical user interfaces with Swing include JButton, JTextField, JTextArea, and containers like JFrame and JPanel. Swing components are considered lightweight compared to the heavier AWT components and provide more flexible and powerful GUI construction capabilities.

Uploaded by

Krishna Krishna
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)
42 views10 pages

SWING

Java Swing is a GUI widget toolkit for Java that is built on top of the Abstract Window Toolkit (AWT) and provides a more sophisticated set of GUI components that are platform independent, lightweight, and follow the model-view-controller framework. Key classes for building graphical user interfaces with Swing include JButton, JTextField, JTextArea, and containers like JFrame and JPanel. Swing components are considered lightweight compared to the heavier AWT components and provide more flexible and powerful GUI construction capabilities.

Uploaded by

Krishna Krishna
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/ 10

SWING

Java Swing is a part of Java Foundation


Class(JFC).

JFC is used to create window-based


applications. (OS like MS Windows 11,
MAC OS)

It built on the top of AWT (Abstract


Windowing Toolkit) API and entirely
written in JAVA.

Unlike AWT, JAVA SWING provides


platform independent and lightweight
components.
The javax.swing package provides
classes for java swing API such as
JButton, JTextField, JTextArea,
JRadioButton, JCheckbox, JMenu,
JColorChooser etc.

What is JFC

Java Foundation classes (JFC) are a set


of GUI(Graphical User Interface)
components which simplify the
development of desktop application.
Differences between JAVA AWT and
JAVA SWING.

No JAVA AWT JAVA SWING

1. AWT Components Java Swing


are platform- components are
dependent. platform-
independent.
2. Heavy Weight Light weight
3. Doesn’t Support Supports pluggable
pluggable look and look and feel.
feel.
4. Provides less Provides more
Components. powerful
components.
5. Doesn’t follows Swing follows
MVC (Model View MVC.
Control)
Hierarchy of Java Swing classes:-
Java Swing Example:

There are two ways to create frame.

By Creating the object of Frame


class(Associaion)

By Extending Frame Class


(Inheritance)

Simple Example:-

We are creating one button and adding


it on the JFrame object inside the
main() method.

import javax.swing.*;
public class FirstSwing{
public static void main(String[] args){
JFrame f = new JFrame(); //Creating
instance of JFrame

JButton b = new JButton (“Login”);//


Creating instance of JButton

b.setBounds(130,100,100,40);// 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 farme
visible
}
}
O/P:-
Serialization and Deserialization in
Java:

Serialization

It is a mechanism of writing the state of


an object into byte-stream.

It is mainly used in RMI, EJB, JMS


technologies.

Deserialization

The reverse operation of serialization is


called deserialization.

Byte-stream is converted into an object.


The Serialization and deserialization
process is platform- independent.

Serialization and deserialization can


perform on different platform.

For Serializing the object, we call the


writeObject() method of
ObjectOutputStream class.

For Deserialization we call the


readObject() method of
ObjectInputStream class.
Example:

import java.io.Serializable;
public class Student implements
Serializable{
int id;
String name;
Public Student (int id, String name)
{
this.id = id;
this.name = name;
}
}

You might also like