Applet Programming
Applet Programming
- no main() method.
- - applet have strict security rules that are enforced by the web browser
Web browser वर Run करण्यासाठी वापरतात, graphics animation sound साठी applet
वापरतात Smart Task साठी वापरतात game play करण्यासाठी वापरतात local computer
वर काम होत नाही.
Applet //class
applet //Method
- Init()
Start()
Stop()
Import java.applet.*;
Init() at first
- Start() then
Paint() then
Stop() then
Paint syntax
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.
.............
.............
(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.
.............
.............
(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.
.............
.............
(Action)
Test.java
/*
This java example shows how to create and run Hello World Java Applet.
*/
import java.applet.Applet;
import java.awt.Graphics;
</APPLET> */
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");
}
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> */