VAPPLET
VAPPLET
APPET APPLICATION
ITS NOT A FULLFEATURED JAVA PROGRAM. ITS A FULLFEATURED JAVA PROGRAM.
TO RUN JAVA APPLET MAIN() IS NOT REQUIRED. TO RUN JAVA APPLICATION MAIN() IS REQUIRED.
APPLET IS COMPARED TO SMALL PROGRAM. ITS NORMALLY WRITTEN TO ACHIEVED BIG OR
SMALL TASK.
APPLETS ARE NOT ALLOWED TO SHARED LIBRARIS APPLICATION HAS ALLOWED TO SHARED
OF OTHER LANGUAGES. LIBRARIS OF OTHER LANGUAGES C,C++ .
NORMALLY GRAPHICS PROGRAMS ARE WRITTEN NORMALLY NON GRAPHICS PROGRAMS ARE
AS AN APPLET PROGRAM. WRITTEN AS AN APPLICATION PROGRAM.
IT IS RUN BY JAVA APPLICATION CAN BE RUN BY “JAVA
“APPLETVIEWER”,”NETSCAPE”,”HOTJAVA INTERPRETER”.
BROWSER” ETC.
IT CAN NOT ACCESS RESOURCE ,FILES IT CAN ACCESS RESOURCE,FILES
• Java applet inherits a set of default behaviour from Applet class. So when an applet is loaded,
it undergoes a series of changes in its state.
The applet states include:
o Born or initialization state
o Running state
o Idle state
o Dead or destroyed state
• INIT method:
METHOD DESCRIPTION
– To Compile
• javac Welcome.java
• If no errors, bytecodes stored in Welcome.class
– Create an HTML file
• Loads the applet into appletviewer or a browser
• Ends in .htm or .html
– To execute an applet
• Create an HTML file indicating which applet the browser (or appletviewer)
should load and execute
(Welcome.html)
Below the applet window there is a small rectangle window,this window is called status window.
Syntax:
void showStatus(String s)
showStatus window is used as one of the helpful debugging aid by displaying various message in
status window.
Status window is a good place to give the user feedback about what is occuring in the applet
window.
import java.awt.*;
import java.applet.*;
public class Status extends Applet
{
public void init()
{
setBackground(Color.BLUE);
}
public void paint(Graphics g)
{
g.setColor(Color.YELLOW);
g.drawString(“ Applet window”,100,100);
showStatus(“ Status window”);
}
}/*<applet code=Status.class height=300,width=300>
</applet>
*/
To pass the parameter param tag is required. Pass more value we required more param tag.
A great benefit of passing parameter from HTML pages to the applets they call its portability.
The area between the opening and closing applet tag is also includes to pass parameter to
applets.
String getParameter(argument);
Wrie an Applet program to display string ”welcome to applet “ .pass string as a parameter to
applet.
Program:
import java.awt.*;
import java.applet.*;
public class ParameterPassing extends Applet
{
String S;
public void init()
{
setBackground(Color.black);
S=getParameter(“ t1 “);
}
1. import java.awt.*;
2. import java.applet.*;
3. /*<applet code =InputData width=300 height=300>
4. </applet>*/
5. public class InputData extends Applet
6. { int x,y,z;
7. TextField t1,t2,t3;
8. public void init()
9. {
10. t1 =new TextField(20);
11. t2 =new TextField(20);
12. t3 =new TextField(20);
13. add(t1);
14. add(t2);
15. add(t3);
16. t1.setText("0");
17. t2.setText("0");
18. t3.setText("0");
19. }
20. public void paint(Graphics g)
21. {
22. g.drawString("enter the numbers: ",10,50);
23. try
24. {
25. x=Integer.parseInt(t1.getText());
26. y=Integer.parseInt(t2.getText());
27. }
28. catch (NumberFormatException e)
29. {
30. g.drawString(" The user had not Entered no: ",100,200);
31. }
32. z=x+y;
33. t3.setText(“ ”+z);
34. }
35. public boolean action(Event e,Object o)
36. {
37. repaint();
38. return true;
39. }
40. }
import java.applet.*;
import java.awt.*;
public class Welcome extends Applet
{
///Font f;
public void init()
{
///f=new Font("Lucida Handwriting",Font.BOLD,24);
///setFont(f);
///setBackground(new Color(44,82,211));
///setForeground(new Color(208,56,34));
}
public void paint (Graphics g)
{
g.setColor(Color.red);
g.drawOval(100,100,71,71);
g.setColor(Color.blue);
g.drawRect(111,111,50,50);
g.drawString(“square inside a circle.”,111,190);
}
}
/*<applet code=Welcome.class width=500 height=500>
</applet>
*/
Html file:
<html>
<body>
<applet code=Hello.class width=500 height=500>
</applet>
</body>
</html>
------------------------------------------------------------------------------------------
/* A simple banner applet.
This applet creates a thread that scrolls
the message contained in msg right to left
across the applet's window.
*/
import java.awt.*;
import java.applet.*;
/*
<applet code="SimpleBanner" width=300 height=50>
</applet>
*/
public class SimpleBanner extends Applet implements Runnable {
String msg = " A Simple Moving Banner.";
Thread t = null;
int state;
boolean stopFlag;
// Set colors and initialize thread.