Appletviewer
Appletviewer is a tool provided by Java Development Kit used to run and test Java
applets without using a web browser.
It executes Java Applet programs directly from an HTML file.
1. Definition
Appletviewer is a Java utility tool that allows programmers to run and test applets created
using Java.
It displays the output of an applet in a small window.
Important Note
Modern Java versions no longer support applets because browsers stopped supporting
them. Applets were mainly used in older Java GUI programs.
Native GUI components are user interface elements provided by the operating system
(OS) such as Windows, Linux, or macOS.
When a program uses native components, the operating system creates and manages the
component.
Difference Between AWT and Swing in Java
Both Abstract Window Toolkit (AWT) and Java Swing are GUI libraries in the Java
Platform used to create desktop applications.
How MVC is Related to Java Swing
Java Swing internally follows the Model–View–Controller (MVC) architecture to separate
data, user interface, and control logic.
MVC Connection (Model–View–Controller)
In Model–View–Controller, the application is divided into three parts:
Model → Stores data
Responsibilities
Stores application data
Communicates with the database
Performs calculations or business logic
Example
Student information
Product details
User account data
View → Displays UI
Responsibilities
Shows information to the user
Receives user input
Examples
Web pages (HTML, JSP)
Swing components like JFrame, JButton, JTable
Angular templates
Controller → Handles user actions
Responsibilities
Receives user requests
Processes input
Updates the model
Sends data to the view
Examples
Event listeners in Swing (ActionListener)
Servlets in Java web applications
DISPOSE_ON_CLOSE
Closes the current window only.
The window resources are released from memory.
The program may continue running if other windows exist.
HIDE_ON_CLOSE
Hides the window, but it is not destroyed.
The window still exists in memory.
It can be shown again using setVisible(true).
DO_NOTHING_ON_CLOSE
Nothing happens when the close button is clicked.
The program must handle the closing event manually.
What is Layout Manager in Java Swing?
In Java Swing, a Layout Manager controls how components (buttons, labels, text
fields, etc.) are arranged inside a container like a JFrame or JPanel.
Instead of manually setting positions, Java uses layout managers to automatically
arrange components.
Common layout managers:
FlowLayout
BorderLayout
GridLayout
CardLayout
BoxLayout
[Link](new FlowLayout());
jfrm → a JFrame object (main window)
setLayout() → method used to set the layout manager
new FlowLayout() → creates a FlowLayout layout manager
painting in swing
class PaintPanel extends JPanel
Why?
Because custom painting in Swing is usually done on a JPanel.
So PaintPanel becomes a custom drawing panel.
Insets ins
Stores the border space of the panel.
Example border areas:
top
left right
bottom
[Link](g);
Purpose:
✔ Clears previous drawings
✔ Ensures proper rendering
Key Concepts to Remember
1. JPanel → for drawing
2. paintComponent() → where drawing happens
3. Graphics object → used to draw shapes