📄 txtcolor.java
字号:
import java.awt.*;
import java.applet.*;
import java.util.Date;
import java.net.*;
import java.io.*;
public class TxtColor extends java.applet.Applet implements Runnable
{
Thread textThread=null;
int Red, Green,Blue;
int stringX, stringY;
int FontSize=16;
String Text="Hello,How Are You !";
Dimension rectSize;
FontMetrics fm;
public void init()
{
Red=255;
Green=255;
Blue=255;
// setFont(new Font("Helvetica",Font.BOLD,16));
setFont(new Font("Helvetica",Font.BOLD,FontSize));
fm=getFontMetrics(getFont());
rectSize=size();
stringY=rectSize.height;
stringX=0;
setBackground(Color.white);
}
public void start()
{
if (textThread==null)
{
textThread=new Thread(this,"text");
textThread.start();
}
}
public void run()
{
while (Thread.currentThread()==textThread)
//因只有一个线程,也可while (True)
{
repaint();
//重绘一次,停一会
try {
textThread.sleep(100);
}
catch(InterruptedException e)
{
}
}
}
public void update(Graphics g)
//消除闪烁,清除指定范围
{
g.clipRect(stringX,stringY-fm.getAscent(),rectSize.width,fm.getHeight());
g.clearRect(stringX,stringY-fm.getAscent(),rectSize.width,fm.getHeight());
paint(g);
}
public void paint(Graphics g)
{
if (stringY<=0)
{
stringY=rectSize.height;
// stringY++;
}
stringY--;
//*****************开始颜色变换************
Color textColor=new Color(Red,Green,Blue);
setFont(new Font("Helvetica",Font.BOLD,FontSize));
FontSize++;
if(FontSize>72);
{FontSize=16;
}
g.setColor(textColor);
g.drawString(Text,stringX,stringY);
if (stringY<rectSize.height/2)/*如在上半屏幕*/
{
if(Green>=255)
{
Green=255;
Red=255;
Blue=255;
}
else
{
Green=Green+3;
Red=Red+3;
Blue=Blue+3;
}
}
else
{
if(Green<=0)
{
Green=0;
Red=0;
Blue=0;
}
else
{
Green=Green-3;
Red=Red-3;
Blue=Blue-3;
}
}
//******************颜色变换End*******
}
public void stop()
{
textThread=null;
}
public boolean mouseEnter(Event event,int x,int y)
{
showStatus("Your Mouse Is Enter Applet Panel !");
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -