OOPS
OOPS
2
INTRODUCTION
In Java, Swing is a GUI toolkit that allows you to create
graphical user interfaces. While JApplet is part of the
AWT (Abstract Window Toolkit) and can be used to create
applets, it has been largely deprecated since Java 9
because applets rely on browser plugins, which are no
longer supported by modern browsers.
Instead of using JApplet, it's better to focus on Swing
components such as JFrame, JPanel, etc., to create
standalone GUI applications. If you still need to work with
JApplet for legacy reasons, it is essentially a specialized
Swing version of the Applet class, and you can use
Swing components within it.
JApplet:
•Part of the deprecated Applet API.
•Mainly used in browser-based Java applications.
•Not recommended for modern development.
JFrame:
•A Swing-based standalone window.
•Preferred for creating desktop applications.
CODE
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
public class JAppletDemo extends Japplet implements
ActionListener{
Jbutton b;
JTextField tf;
public void init(){
tf=new JTextField();
tf.setBounds(30,40,150,20);
5
b=new Jbutton(“Click ME”);
b.setBounds(80,150,70,40);
add(b);
add(tf);
b.addActionListener(this);
setLayout(null);
}
public void actionPerformed(ActionEvent e)
{
tf.setText(“Welcome to Japplet”);
}
}
6
OUTPUT
7
KEY FEATURES
1.Encapsulation: The GUI setup is encapsulated within the init
method of the MyJApplet class.
CONCLUSION
JApplet is a Swing-based extension of the AWT Applet class, allowing the use of
modern Swing components like JLabel and JButton in applet-based applications. It was
designed to create interactive GUIs embedded in web browsers. However, JApplet and
applets have been deprecated since Java 9 due to declining browser support, security
vulnerabilities, and the rise of modern web technologies. Today, JFrame is the preferred
choice for standalone GUI applications in Swing. For more advanced and flexible user
interface development, developers are encouraged to transition to frameworks like
JavaFX, which offer better support for contemporary application needs.
THANK YOU