Here’s a clear, exam-ready detailed summary of your NPTEL Programming in Java – Lecture 46 (Java Swing Demo XVII)
Java Swing Demonstration – Detailed Summary
1. What is Java Swing?
• Java Swing is used to create GUI (Graphical User Interface) applications.
• It is more powerful than AWT because:
o Provides rich components
o Supports customization
o Has built-in functionalities
2. Basic Components Used
To use Swing:
[Link].*;
import [Link].*;
Main Components:
• JFrame → Main window (container)
• JPanel → Sub-container to hold components
• JButton → Button
• JLabel → Text label
Structure:
JFrame → JPanel → Components (Button, Label, etc.)
3. Creating a Simple GUI
Steps:
1. Create JFrame
2. Create JPanel
3. Add components (Button, Label)
4. Add panel to frame
5. Set size & visibility
4. Different Ways to Create GUI
✔ Method 1: Using Constructor
• GUI created inside class constructor
• Object creation automatically builds GUI
Advantage:
• Code reuse (modular design)
✔ Method 2: Extending JFrame
class Demo extends JFrame
• No need to create separate frame object
• Components directly added using add()
Advantage:
• Cleaner & preferred approach
5. JButton Usage
✔ Simple Button
• Create button and add to frame
✔ Button with ActionListener (Event Handling)
[Link](...)
• Executes code when button is clicked
Example:
• Print message: "Welcome to Java"
✔ Button with Image
• Use ImageIcon
new JButton(new ImageIcon("path"))
Used for:
• Icons, logos, UI enhancement
6. Text Components
✔ JTextField
• Used for input
• Example: Calculator (Addition/Subtraction)
✔ JTextArea
• Used for:
o Word count
o Character count
✔ JPasswordField
• Used in login systems
• Input is hidden (secure)
Example:
• Username + Password GUI
7. Selection Components
✔ JCheckBox
• Multiple selections allowed
• Example:
o Java ✔
o C++ ✔
✔ JRadioButton
• Only one selection at a time
• Circular buttons
Difference:
Component Selection
CheckBox Multiple
RadioButton Single
8. JSpinner (Numeric Input)
• Used for numeric range selection
• Has:
o Initial value
o Min value
o Max value
o Step increment
Example:
• Range: 0 to 10
• Step: 1 or 0.5
9. JToggleButton
• Works like ON/OFF switch
• Changes state on click
Example:
• ON → OFF → ON
Uses:
• Settings toggle
• Enable/disable options
10. Event Handling
• Important for interaction
• Types:
o ActionListener → Button click
o ItemListener → Toggle/Selection change
11. Key Advantages of Swing
• Rich GUI components
• Customizable UI
• Built-in features (calculator, login, etc.)
• Platform independent
Final Quick Revision (1-Minute)
• Swing = GUI toolkit
• JFrame = main window
• JPanel = container
• JButton = button (with events/images)
• JTextField = input
• PasswordField = secure input
• CheckBox = multiple select
• RadioButton = single select
• Spinner = numeric input
• ToggleButton = ON/OFF
• Event handling = interaction
Got it — here’s a combined, detailed + exam-ready summary of Lecture 46 & 47 (Java Swing Demonstrations XVII + XVIII) in a clean structured
way.
Java Swing (Lecture 46 + 47) – Complete Detailed Summary
1. What is Java Swing?
• Swing is a GUI toolkit in Java used to build desktop applications.
• More powerful than AWT because:
o Rich components (buttons, tables, menus, etc.)
o Platform independent
o Customizable UI
2. Core Structure of Swing GUI
Basic hierarchy:
JFrame → JPanel → Components
✔ Main Components:
• JFrame → Main window
• JPanel → Container inside frame
• JLabel → Text display
• JButton → Clickable button
3. Ways to Create GUI
✔ Method 1: Constructor-based
• GUI created inside constructor
• Object creation → GUI automatically created
✔ Method 2: Extending JFrame
class Demo extends JFrame
• No need to create separate frame object
• Cleaner & widely used
4. Event Handling
• Used for interaction
• Types:
o ActionListener → Button click
o ItemListener → Selection change
o MouseListener → Mouse events
5. Swing Input & Button Components
✔ JButton
• Simple button
• Can add:
o ActionListener
o Image (using ImageIcon)
✔ JTextField
• Single-line input
• Used in calculator, forms
✔ JTextArea
• Multi-line input
• Used for:
o Word count
o Character count
✔ JPasswordField
• Secure input (hidden text)
• Used in login forms
6. Selection Components
✔ JCheckBox
• Multiple selection allowed
✔ JRadioButton
• Only one selection (grouped)
7. Advanced Input Components
✔ JSpinner
• Numeric input with range
• Example:
o Min = 0, Max = 10, Step = 1
✔ JToggleButton
• ON/OFF type button
✔ JComboBox
• Dropdown list
• Stores items in array or dynamically
✔ JList
• List of selectable items
• Supports:
o Single selection
o Multiple selection (Ctrl key)
✔ JSlider
• Select value by sliding
• Range-based input (e.g., 0–50)
8. Data Display Components
✔ JTable
• Displays data in rows & columns
• Uses:
o 2D array (data)
o Column headers
✔ JTree
• Displays hierarchical data (tree structure)
• Example:
o Root → Child → Sub-child
9. Dialog & Utility Components
✔ JOptionPane
• Popup dialog box
• Used for:
o Messages
o Alerts
o Errors
✔ JColorChooser
• Select colors using GUI
• Supports:
o RGB, HSB formats
• Used to change background, text color
10. Menu Components
✔ JMenuBar
• Top menu bar
✔ JMenu
• Menu (File, Edit, etc.)
✔ JMenuItem
• Options inside menu
✔ Popup Menu (JPopupMenu)
• Appears on mouse click (right-click)
✔ CheckBox Menu Item
• Menu option with checkbox
• Can toggle selection
11. Container & Layout Components
✔ JTabbedPane
• Multiple tabs in one window
• Example:
o Home | Visit | Help
12. Progress & Dynamic Components
✔ JProgressBar
• Shows progress of task
• Controlled via loop (0 → max)
13. Key Programming Concepts
✔ Adding Components
[Link](component);
✔ Setting Properties
[Link]();
[Link]();
[Link](true);
✔ Event Example
[Link](e -> {
[Link]("Clicked");
});
Real-world Applications Covered
• Calculator (TextField + Button)
• Login form (TextField + PasswordField)
• Word counter (TextArea)
• Menu-driven apps
• Color picker tools
• File explorer (Tree structure)
Quick Revision (Interview / Exam)
• Swing = GUI toolkit
• JFrame = window
• JPanel = container
• JButton = action
• JTextField = input
• JTable = data display
• JComboBox = dropdown
• JList = list
• JSlider = range input
• JOptionPane = popup
• JMenuBar = menu system
• JTree = hierarchy
• JTabbedPane = tabs
• JProgressBar = progress
Final Conclusion
• Swing provides complete GUI development toolkit
• Supports:
o Input handling
o Event-driven programming
o Complex UI components
• Requires practice + event handling understanding
Here’s a complete, structured + exam-ready detailed summary of Lecture 48 (Networking in Java)
Java Networking – Detailed Summary (Lecture 48)
1. What is Networking?
• Networking = communication between two or more computers
• Used for:
o File sharing
o Messaging
o Resource sharing
In Java:
• We can write programs to enable communication between systems
2. Types of Networks
Type Range Example
LAN (Local Area Network) 1–10 km College, office
MAN (Metropolitan Area Network) 10–40 km City networks
WAN (Wide Area Network) 40+ km Internet
3. Important Networking Terminologies
✔ IP Address
• Unique logical address of a computer
• Example:
[Link]
✔ Port Number
• Identifies application on a system
• Example:
80 (HTTP), 25 (SMTP)
✔ MAC Address
• Physical address (given by manufacturer)
• Unique for each device
✔ URL (Uniform Resource Locator)
• Address of a resource on internet
Structure:
protocol://domain/resource
Example:
[Link]
✔ Socket
• Combination of:
IP Address + Port Number
• Used for communication between systems
4. WWW (World Wide Web)
• Collection of web documents (HTML, PHP, etc.)
• Accessed using browsers
• Works over Internet
5. Communication Protocols
✔ Connection-Oriented (Reliable)
• Example: TCP
• Steps:
1. Connection established
2. Data sent
3. Connection closed
Features:
• Reliable
• Slower
✔ Connectionless (Fast)
• Example: UDP
• No connection setup
Features:
• Faster
• Less reliable
✔ Important Protocols
Protocol Use
TCP Reliable communication
Protocol Use
UDP Fast communication
HTTP Web pages
HTTPS Secure web
FTP File transfer
SMTP Email sending
6. Java Networking Package
import [Link].*;
7. Important Classes in Java Networking
1. URL Class
• Represents a web address
Methods:
• getProtocol()
• getHost()
• getPort()
• getFile()
Use:
• Extract parts of URL
2. URLConnection
• Establishes connection to resource
Important Methods:
• openConnection()
• getInputStream()
Use:
• Read data from web server
3. HttpURLConnection
• Specialized for HTTP protocol
Used for:
• Web communication (browser-like)
4. InetAddress
• Represents IP address
Methods:
• getHostName()
• getHostAddress()
Use:
• Identify machine on network
8. Socket Programming in Java
Two Types:
A. Datagram Socket (UDP)
• Uses connectionless communication
Classes:
• DatagramSocket
• DatagramPacket
Working:
1. Data divided into packets
2. Sent independently
3. May arrive out of order
B. Stream Socket (TCP)
• Uses connection-oriented communication
Classes:
• ServerSocket
• Socket
9. Client-Server Model
✔ Server
• Waits for requests
ServerSocket ss = new ServerSocket(port);
Socket s = [Link]();
✔ Client
• Sends request
Socket s = new Socket("localhost", port);
✔ Communication
• Uses streams:
InputStream / OutputStream
10. Datagram Example (UDP)
Sender:
• Create message
• Convert to packet
• Send using DatagramSocket
Receiver:
• Receive packet
• Extract data
11. TCP Example (Client-Server)
Steps:
1. Server starts
2. Client connects
3. Data exchanged
12. Dialogue Communication
• Client ↔ Server interaction
• Continuous message exchange
13. Concurrent Server
• Handles multiple clients at same time
• Uses Threads
Flow:
• Accept client
• Create thread
• Handle independently
14. Key Differences: TCP vs UDP
Feature TCP UDP
Connection Yes No
Speed Slow Fast
Reliability High Low
Use File transfer Streaming
Final Quick Revision
• Networking = communication between systems
• IP = unique system address
• Port = application identifier
• Socket = IP + Port
• TCP = reliable
• UDP = fast
• URL = web address
• [Link] = networking package
• ServerSocket = server
• Socket = client
• DatagramSocket = UDP communication
Conclusion
• Java provides powerful network programming support
• Supports:
o TCP (reliable)
o UDP (fast)
• Enables:
o Client-server apps
o File transfer
o Web communication