?? shadowtext.java
字號:
import java.awt.*;
import java.applet.*;
public class ShadowText extends Applet implements Runnable
{
private Image img;
private Image offI;
private Graphics offG;
private Thread thread = null;
private MediaTracker imageTracker;
private int height,width;
private String text;
private int FontSize;
private Font font;
private int textcolor, backcolor, shadowcolor;
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));
img = createImage(width,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);
imageTracker = new MediaTracker(this);
imageTracker.addImage(img,0);
try
{
imageTracker.waitForID(0);
}
catch(InterruptedException e){}
offI = createImage(width,height);
offG = offI.getGraphics();
}
public void start()
{
if(thread == null)
{
thread = new Thread(this);
thread.start();
}
}
public void run()
{
int x=width;
while(thread != null)
{
try
{
offG.drawImage(img,x,0,this);
repaint();
thread.sleep(50);
}
catch(InterruptedException e){}
x-=3;
if(x < -width)
{
x = width;
}
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
g.drawImage(offI,0,0,this);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -