Applet programming
-An applet is a Java Program that Run in a web browser
- An applet is a java class that extends the Java.applet.Applet class
- no main() method.
- applets are designed to be embedded within an HTML page
- -JVM is required to view an applet
- - applet have strict security rules that are enforced by the web browser
- HTML file --------------------Applets java enabled browser
- Class ----------------------java.applet.Applet import..
Web browser वर Run करण्यासाठी वापरतात, graphics animation sound साठी applet
वापरतात Smart Task साठी वापरतात game play करण्यासाठी वापरतात local computer
वर काम होत नाही.
Applet //class
applet //Method
Its are having some required method
- Init()
Start()
Stop()
Import java.applet.*;
Init() at first
- Start() then
Paint() then
Stop() then
Paint syntax
Public void paint(Graphics g)
g.Draw string(“java”,10,10)
Applet life cycle
1. Born or Initialization State: Applets enters the initialization state when it is first loaded.
It is achieved by init() method of Applet class. Then applet is born.
public void init()
.............
.............
(Action)
2. Running State: Applet enters the running state when the system calls the start() method
of Applet class. This occurs automatically after the applet is initialized.
public void start()
.............
.............
(Action)
}
3. Idle State: An applet becomes idle when it is stopped from running. Stopping occurs
automatically when we leave the page containing the currently running applet. This is
achieved by calling the stop() method explicitly.
public void stop()
.............
.............
(Action)
4. Dead State: An applet is said to be dead when it is removed from memory. This occurs
automatically by invoking the destroy() method when we want to quit the browser.
public void destroy()
.............
.............
(Action)
Test.java
Hello word program
/*
Hello World Applet Example
This java example shows how to create and run Hello World Java Applet.
*/
import java.applet.Applet;
import java.awt.Graphics;
/*<APPLET CODE =Test width=100 height=100>
</APPLET> */
public class Test extends Applet{
public void paint(Graphics g){
g.drawString("Hello World", 50, 50);
Graphics
import java.applet.Applet;
import java.awt.*;
public class GraphicsDemo extends Applet{
public void paint(Graphics g){
g.setColor(Color.red);
g.drawString("Welcome",50, 50);
g.drawLine(20,30,20,300);
g.drawRect(70,100,30,30);
g.fillRect(170,100,30,30);
g.drawOval(70,200,30,30);
g.setColor(Color.pink);
g.fillOval(170,200,30,30);
g.drawArc(90,150,30,30,30,270);
g.fillArc(270,150,30,30,0,180);
}
}
/*
<applet code="GraphicsDemo.class" width="300" height="300">
</applet>
*/
Param Tag.
import java.applet.Applet;
import java.awt.Graphics;
public class UseParam extends Applet{
public void paint(Graphics g){
String str=getParameter("msg");
g.drawString(str,50, 50);
}
}
//<html>
//<body>
/*<applet code="UseParam.class" width="300" height="300">
<param name="msg" value="Welcome to applet">
</applet> */
//</body>
//</html>
User input
import java.awt.*;
import java.applet.*;
public class User_input extends Applet
{
String unm;
public void init()
{
unm=getParameter("unm");
}
public void paint(Graphics g)
{
g.drawString("Ganesh "+unm,50,50);
}
}
/* <applet code = "User_input.class" height = 500 width =500>
<param name="unm" value="Vedant">
</applet> */
Font Class
import java.awt.*;
import java.applet.*;
public class fon extends Applet
{
Font f1,f2,f3;
public void init()
{
f1 = new Font("Arial",Font.BOLD,18);
f2 = new Font("Forte",Font.PLAIN,24);
f3 = new Font("Elephant",Font.ITALIC,28);
}
public void paint(Graphics g)
{
g.drawString("Ganesh",50,50);
g.setFont(f1);
g.drawString("Aarushi",50,80);
g.setFont(f2);
g.drawString("Swati",50,110);
g.setFont(f3);
g.drawString("Advik",50,140);
}
}
/* <applet code = "fon.class" height = 500 width =500>
</applet> */