[JAVA100例]073、传递参数

向日葵乐妈咪

向日葵乐妈咪

2016-02-19 15:34

在这个颜值当道,屌丝闪边的时代,拼不过颜值拼内涵,只有知识丰富才能提升一个人的内在气质和修养,所谓人丑就要多学习,今天图老师给大家分享[JAVA100例]073、传递参数,希望可以对大家能有小小的帮助。

  

import java.awt.*;
import java.applet.*;
/**
 * pTitle: 带阴影的文字/p
 * pDescription: 使用Applet和Graphics,实现一个文字的移动广告。/p
 * pCopyright: Copyright (c) 2003/p
 * pFilename: 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方法说明:Applet初始化,浏览器加载Applet是调用。
 *br输入参数:
 *br返回类型:
 */ 
 public void init()
 {  
  width = this.size().width;
  height = this.size().height;
  //获取显示信息
  String s = new String(getParameter("Text"));
  
  text = new String("Hello");
  if(s != null)
   text = s;
  //获取字体大小
  FontSize = 30;
  s = new String(getParameter("FontSize"));
  if(s != null)
   FontSize = Integer.parseInt(s);
  //获得字体颜色
  s = getParameter("Fore");
  textcolor = (s==null) ? 0x000000 : Integer.parseInt(s, 16);
  //获取背景颜色
  s = getParameter("Back");
  backcolor = (s==null) ? 0x000000 : Integer.parseInt(s, 16);
  //获取阴影颜色
  s = getParameter("shadow");
  shadowcolor = (s==null) ? 0x000000 : Integer.parseInt(s, 16);
  //设置背景颜色
  this.setBackground(new Color(backcolor));
  //使用Graphics创建一张图片
  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);
  
  //构造可控制的图片对象     
  offI = createImage(width,height);
  offG = offI.getGraphics();
  
 }
/**
 *br方法说明:重载start()方法,启动线程
 *br输入参数:
 *br返回类型:
 */ 
 public void start()
 {
  if(thread == null)
  {
   thread = new Thread(this);
   thread.start();
  }
 }
/**
 *br方法说明:线程体。绘制屏幕
 *br输入参数:
 *br返回类型:
 */ 
 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方法说明:Appletg更新画面调用的方法
 *br输入参数:Graphics g 绘图对象
 *br返回类型:
 */ 
 public void update(Graphics g)
 {
  paint(g);
 }
/**
 *br方法说明:Applet绘制屏幕的方法
 *br输入参数:
 *br返回类型:
 */ 
 public void paint(Graphics g)
 {
  g.drawImage(offI,0,0,this);
 }
}

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)
展开更多 50%)
分享

猜你喜欢

[JAVA100例]073、传递参数

编程语言 网络编程
[JAVA100例]073、传递参数

[JAVA100例]001、Hello,Java

编程语言 网络编程
[JAVA100例]001、Hello,Java

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

[JAVA100例]060、继承Thread

编程语言 网络编程
[JAVA100例]060、继承Thread

[JAVA100例]011、按钮

编程语言 网络编程
[JAVA100例]011、按钮

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

[JAVA100例]061、实现Runnable

编程语言 网络编程
[JAVA100例]061、实现Runnable

[JAVA100例]037、读取随机文件

编程语言 网络编程
[JAVA100例]037、读取随机文件

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

如何手动添加和删除Windows服务

如何手动添加和删除Windows服务

AJAX应用演示和源码下载站点经典汇合

AJAX应用演示和源码下载站点经典汇合
下拉加载更多内容 ↓