[JAVA100 example]073, pass parameter

Source: Internet
Author: User
Tags set background

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);


 }


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.