站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Java 专题绕四边运动的文字

绕四边运动的文字

摘要: 绕四边运动的文字

</td> </tr> <tr> <td width="507" height="35" valign="top" class="ArticleTeitle"> //绕屏幕四边运动的文字。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;

public class ChenWin11 extends JApplet implements Runnable
{
int width=0;
int height=0;
int length=0;
int delay=125;
int point_size=25;
String message="This is ChenWin11!";
String font_to_use="TimesRpman";
char char_array[];
int offset_x[];
int offset_y[];
Thread mythread;
public void init()
{ setBackground(Color.green);
length=message.length();
char_array=new char[length];
message.getChars(0,length,char_array,0);
offset_x=new int[length];
offset_y=new int[length];
}
public void start()
{ mythread=new Thread(this);
mythread.start();
}
void get_defaults()
{
width=getSize().width;
height=getSize().height;
}
public void re_draw()
{
repaint();
try
{
Thread.sleep(delay);
}
catch(InterruptedException e)
{
}
}
public void run()
{
while(true)
{
for(int y1=height-point_size;y1>point_size;y1-=point_size)
{
int j=-1;
for(int i=0;i {
if(y1+i*point_size>height-point_size)
{if(j<0)
j=i;
offset_y[i]=height-point_size;
offset_x[i]=(i-j+2)*point_size;
}
else
{
offset_y[i]=y1+i*point_size;
offset_x[i]=point_size;
}
}
re_draw();
}
for(int x1=point_size;x1 {
int j=-1;
for(int i=0;i {
if(x1-i*point_size {if(j<0)
j=i;
offset_y[i]=(i-j+1)*point_size;
offset_x[i]=point_size;
}
else
{
offset_y[i]=point_size;
offset_x[i]=x1-i*point_size;
}
}
re_draw();
}
for(int y1=point_size*2;y1 {
int j=-1;
for(int i=0;i {
if(y1-i*point_size {if(j<0)
j=i;
offset_y[i]=point_size;
offset_x[i]=width-(i-j+2)*point_size;
}
else
{
offset_y[i]=y1-i*point_size;
offset_x[i]=width-point_size;
}
}
re_draw();
}
for(int x1=width-point_size;x1>point_size;x1-=point_size)
{
int j=-1;
for(int i=0;i {
if(x1+i*point_size>width-point_size*2)
{if(j<0)
j=i;
offset_y[i]=height-(i-j+1)*point_size;
offset_x[i]=width-point_size;
}
else
{
offset_y[i]=height-point_size;
offset_x[i]=x1+i*point_size;
}
}
re_draw();
}
}
}

public void paint(Graphics g)
{

get_defaults();
Graphics2D g2d=(Graphics2D)g;

BufferedImage bi=new BufferedImage(
getWidth(),getHeight(),BufferedImage.TYPE_INT_ARGB);


Graphics2D g2d1=bi.createGraphics();

Font font=new Font(font_to_use,Font.PLAIN,point_size);
g2d1.setFont(font);
g2d1.clearRect(0,0,width,80);
g2d1.clearRect(width-80,0,80,height);
g2d1.clearRect(0,height-80,width,80);
g2d1.clearRect(0,0,80,height);
g2d1.setColor(Color.blue);
for(int i=0;i g2d1.drawChars(char_array,i,1,offset_x[i],offset_y[i]);
g2d1.setColor(Color.red);
g2d1.drawString("This is ChenWin11",width/4,height/2);

g2d.drawImage(bi,0,0,width,height,this);
}
public void update(Graphics g)
{
paint(g);
}
} </td> <td width="177" valign="top" class="ArticleTeitle">
</td> </tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle">


↑返回目录
前一篇: Robot类测试
后一篇: 按钮的光标设置