0% found this document useful (0 votes)
5 views

oop ppt

Uploaded by

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

oop ppt

Uploaded by

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

Introduction to

JApplet
JApplet is a Java class that allows developers to create interactive, web-
based applications that can be embedded within HTML pages. It provides
a powerful platform for building dynamic, feature-rich content for the
web.

Name: Sohan Mondal

B.Tech (Computer Science and Design)

Roll: 2353
What is JApplet?
1 Java-based Web 2 Interactive Content
Application JApplets can provide
JApplet is a Java-based interactive and dynamic
component that can be content, enhancing the user
embedded within web experience on web pages.
pages, allowing for the
integration of Java
functionality with web
technologies.

3 Reusable Components
JApplet components can be reused across multiple web pages,
promoting code reusability and efficiency.
Key Features and
Capabilities
Interactivity Animations
JApplets can respond to user JApplet can incorporate
input, such as mouse clicks and animations, making web
keyboard events, enabling content more engaging and
dynamic and interactive visually appealing.
experiences.

Data Visualization Multimedia


JApplets can be used to create JApplet can integrate
data visualizations, such as multimedia elements, like
charts and graphs, to present audio and video, to enhance
information effectively. the user experience.
Embedding JApplet in
Web Pages

HTML Integration
JApplets can be seamlessly embedded within HTML pages using the
<applet> or <object> tags.

Java Code
The JApplet class allows developers to write Java code that defines the
functionality and behavior of the web application.

Web Browser Integration


JApplets are executed within the web browser, allowing for a tight
integration between Java and the web environment.
Swing Components in JApplet
Buttons and Controls Panels and Layouts Graphics and Animations

JApplet can leverage Swing Swing's layout managers and panel JApplet can utilize Swing's drawing APIs
components like buttons, text fields, components allow for the organization and animation capabilities to create
and dropdown menus to create and positioning of UI elements within dynamic and visually engaging web
intuitive user interfaces. the JApplet. content.
Example: JApplet with
Swing GUI
1 Design UI
Create the user interface using Swing components, such as
JButton, JTextField, and JPanel.

2 Add Functionality
Implement event handlers and logic to respond to user
interactions within the JApplet.

3 Deploy to Web
Package the JApplet and deploy it to a web server, allowing
it to be embedded in web pages.
Deploying and Running
JApplet
Compile JApplet
1 Compile the Java code that defines the JApplet functionality.

Package JApplet
2 Package the compiled JApplet into a JAR file for deployment.

Host JApplet
3 Host the JApplet JAR file on a web server, making it
accessible to web pages.

Embed in Web Page


4 Embed the JApplet in an HTML page using the <applet> or
<object> tag.
Code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MultiplyApplet extends JApplet implements ActionListener {


JTextField num1 = new JTextField(5), num2 = new JTextField(5), res = new JTextField(10);
JButton resBtn = new JButton("Multiply");

public void init() {


res.setEditable(false);
resBtn.addActionListener(this);
JPanel pan = new JPanel(new GridLayout(4, 2));

// Adding components in one go


for (JComponent[] row : new JComponent[][]{
{new JLabel("Enter Number 1:"), num1},
{new JLabel("Enter Number 2:"), num2},
{resBtn, new JLabel()},
{new JLabel("Result:"), res}}) {
pan.add(row[0]); pan.add(row[1]);
}

// Set font and button color


Font font = num1.getFont().deriveFont(Font.PLAIN, 20);
for (JComponent comp : new JComponent[]{num1, num2, res, resBtn}) comp.setFont(font);
resBtn.setBackground(Color.orange);

add(pan);
}

public void actionPerformed(ActionEvent e) {


try {
res.setText(Integer.toString(
Integer.parseInt(num1.getText()) * Integer.parseInt(num2.getText())
));
} catch (NumberFormatException ex) {
res.setText("Wrong Input");
}
}
}
Output
Thank You

You might also like