[Link].
*;
[Link].*;
publicclassSimpleAppletextends
Applet{
publicvoidpaint(Graphicsg){
[Link]("ASimpleApplet",20,
20);
}
}
[Link].*;
[Link].*;
/*
<appletcode="SimpleApplet"width=200
height=60>
</applet>
*/
publicclassSimpleAppletextends
Applet{
publicvoidpaint(Graphicsg){
330 J a v a 2 : T h e C o m p l e t e R e f e r
ence
THE JAVA LANGUAGE
[Link]("ASimpleApplet",20,
20);
}
}
Method:
void setBackground(Color newColor)
void setForeground(Color newColor)
Here, newColor specifies the new color. The
class Color defines the constants shown
here that can be used to specify colors:
[Link] [Link]
[Link] [Link]
[Link] [Link]
[Link] [Link]
[Link] [Link]
[Link] [Link]
[Link]
[Link].*;
[Link].*;
/*
<appletcode="Sample"width=300
height=50>
</applet>
*/
publicclassSampleextendsApplet{
Stringmsg;
//settheforegroundandbackground
colors.
publicvoidinit(){
setBackground([Link]);
setForeground([Link]);
msg="Insideinit()";
}
//Initializethestringtobe
displayed.
publicvoidstart(){
msg+="Insidestart()";
}
//Displaymsginappletwindow.
publicvoidpaint(Graphicsg){
msg+="Insidepaint().";
[Link](msg,10,30);
}
}
[Link].*;
[Link].*;
/*
<appletcode="SimpleBanner"width=300
height=50>
</applet>
*/
publicclassSimpleBannerextends
AppletimplementsRunnable{
Stringmsg="ASimpleMoving
Banner.";
Threadt=null;
intstate;
booleanstopFlag;
//Setcolorsandinitializethread.
publicvoidinit(){
setBackground([Link]);
setForeground([Link]);
}
//Startthread
publicvoidstart(){
t=newThread(this);
stopFlag=false;
[Link]();
}
//Entrypointforthethreadthatruns
thebanner.
publicvoidrun(){
charch;
//Displaybanner
for(;;){
try{
repaint();
[Link](250);
ch=[Link](0);
msg=[Link](1,[Link]());
msg+=ch;
if(stopFlag)
break;
}catch(InterruptedExceptione){}
}
}
//Pausethebanner.
publicvoidstop(){
stopFlag=true;
t=null;
}
//Displaythebanner.
publicvoidpaint(Graphicsg){
[Link](msg,50,30);
}
}