Java applet - java

RubayaMim 345 views 22 slides Jul 13, 2019
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

basic things about java


Slide Content

Java Applet

Objectives Definition Use of Java Advantages Methods Life Cycle Examples Drawback

What Is Applet? An Applet is a special kind of java program that is designed to be transmitted over the internet and automatically executed by java compatible web browser.

Why We Use Applet In Java? Java Applets are usually used to add small, interactive components or enhancements to a webpage. These may consist of buttons, scrolling text, or stock tickers, but they can also be used to display larger programs like word processors or games.

Advantages of Applet in Java There are many advantages of applet. They are as follows: It works at client side so less response time. Secured It can be executed by browsers running under many plateforms , including Linux, Windows, Mac Os etc.

How to run an Applet? By html file. By appletViewer tool (for testing purpose).

Applet Header Files import java.applet.* import java.awt.*

Methods Function Use init () is used to initialized the Applet. It is invoked only once start() is invoked after the init () method or browser is maximized. It is used to start the Applet. stop() is used to stop the Applet. It is invoked when Applet is stop or browser is minimized. destroy() is used to destroy the Applet. It is invoked only once. paint() is used to paint the Applet

init () The init () method is the first method to be called import java.applet.Applet ; public class First extends Applet { public void init () { } }

paint() import java.applet.Applet ; import java.awt.Graphics ; public class First extends Applet { public void paint(Graphics g){ g.drawString ("Welcome To Our Presentation", 100, 75); } }

Example :01 import java.applet .*; import java.awt .*; public class Drawline extends Applet { public void init () { } public void paint(Graphics g){ g.drawLine (20,20,100,20); g.drawLine (20,20,20,100); } }

Example 02 import java.applet.Applet ; import java.awt .*; public class RECt extends Applet { public void init () { } public void paint(Graphics g){ g.drawRect (70,50,300,200); } }

Example 03 import java.applet *; import java.awt .*; public class Backcolor extends Applet { public void init (){ setBackground ( Color.blue ); } public void paint(Graphics g) { g.setColor ( Color.white ); g.drawString ("JAVA APPLET",40,100); } }

Example 04 import java.applet.Applet ; import java.awt .*; import java.awt.Image ; public class Image_OP extends Applet { Image picture; public void init () { picture= getImage ( getDocumentBase (),"JKKNIU.jpg"); } public void paint(Graphics g){ g.drawImage (picture,50,50,this); } }

Example 05 package applete ; import java.applet.Applet ; import java.awt .*; public class Second extends Applet{ public void paint(Graphics g){ g.setColor ( Color.red ); g.drawString ("Welcome",150, 70); g.drawRect (70,100,40,30); g.fillRect (170,100,30,30); g.drawOval (70,200,30,30); g.setColor ( Color.pink ); g.drawString ("Welcome to my applete program",50, 50); g.fillOval (170,200,30,30); g.drawArc (90,150,30,30,30,270); g.fillArc (270,150,30,30,0,180); } }

Example 06 package applete ; import java.applet .*; import javax.swing .*; import java.awt.event .*; public class EventApplet extends JApplet implements ActionListener { JButton b; JTextField tf ; public void init (){ tf =new JTextField (); tf.setBounds (30,40,150,20); b=new JButton ("Click"); b.setBounds (80,150,70,40); add(b);add( tf ); b.addActionListener (this); setLayout (null); } public void actionPerformed ( ActionEvent e){ tf.setText ("Welcome"); } }

Example 07 package applete ; import java.awt .*; import java.awt.event .*; import java.applet .*; public class Painting extends Applet implements MouseMotionListener { public void init (){ addMouseMotionListener (this); setBackground ( Color.red ); } public void mouseDragged ( MouseEvent me){ Graphics g= getGraphics (); g.setColor ( Color.white ); g.fillOval ( me.getX (), me.getY (),5,5); } public void mouseMoved ( MouseEvent me){} }

Analoge Clock Example 08

Example 09 Digital Clock

Drawback of Applet Plugin is required at client browser to execute applet
Tags