Import java.awt.*;
import java.applet.*;
/**
* <p>title: Shadowed text </p>
* <p>description: Use applets and graphics to implement a text-mobile ad. </p>
* <p>copyright:copyright (c) 2003</p>
* <p>Filename:ShadowText.java</p>
* @version 1.0
*/
public class Shadowtext extends Applet implements Runnable
{
Private Image img;
private Image Offi;
private Graphics OFFG;
private thread thread = NULL;
private int height,width;
private String text;
private int fontsize;
private font font;
private int TextColor, BackColor, Shadowcolor;
/**
*<br> Method Description: Applet initialization, browser loading applet is called.
*<br> input Parameters:
*<br> return type:
*/
public void init ()
{
width = this.size (). width;
height = this.size (). Height;
//Get display information
string s = new string (GetParameter ("Text"));
Text = new String ("Hello");
if (s!= null)
Text = s;
//Get font size
fontsize = 30;
s = new String (GetParameter ("fontsize"));
if (s!= null)
fontsize = Integer.parseint (s);
//Get font color
s = getparameter ("Fore");
TextColor = (s==null)? 0x000000:integer.parseint (S, 16);
//Get background color
s = getparameter ("Back");
BackColor = (s==null)? 0x000000:integer.parseint (S, 16);
//Get shadow color
s = getparameter ("Shadow");
Shadowcolor = (s==null)? 0x000000:integer.parseint (S, 16);
//Set background color
This.setbackground (New Color (BackColor));
//Use graphics to create a picture
img = createimage (width+300,height);
Graphics temp = img.getgraphics ();
Temp.setcolor (New Color (BackColor));
Temp.fillrect (0,0,width,height);
Temp.setcolor (New Color (Shadowcolor));
font = new Font ("Timesroman", font.bold,fontsize);
Temp.setfont (font);
temp.drawstring (TEXT,10,HEIGHT*3/4);
Temp.setcolor (New Color (TextColor));
temp.drawstring (TEXT,10-3,HEIGHT*3/4-3);
//Constructs controllable picture objects
offi = createimage (width,height);
OFFG = Offi.getgraphics ();
}
/**
*<br> Method Description: Overload the Start () method, start the thread
*<br> input Parameters:
*<br> return type:
*/
public void Start ()
{
if (thread = = null)
{
thread = new Thread (this);
Thread.Start ();
}
}
/**
*<br> Method Description: Thread body. Draw Screen
*<br> input Parameters:
*<br> return type:
*/
public void Run ()
{
int x=width;
while (thread!= null)
{
Try
{
offg.drawimage (img,x,0,this);
repaint ();
Thread.Sleep (20);
}
catch (Interruptedexception e) {}
x-=3;
if (x <-img.getwidth (this))
{
x = width;
}
}
}
/**
*<br> Method Description: Appletg Update screen Call method
*<br> input parameter: Graphics g drawing Object
*<br> return type:
*/
public void Update (Graphics g)
{
Paint (g);
}
/**
*<br> Method Description: How the applet draws the screen
*<br> input Parameters:
*<br> return type:
*/
public void Paint (Graphics g)
{
g.drawimage (offi,0,0,this);
}
}