⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coloringtext.java

📁 java applet编程,实现对相关图片声音的调用
💻 JAVA
字号:
import java.awt.*;
import java.applet.*;
import java.util.*;

public class ColoringText extends Applet implements Runnable {
	String msg;
	Font fnt;
	Color clr, spot_clr;

	int strPt = 0;
    int delay;
    Thread animatorThread;

    public void init()
	{
        String str;
        int fps = 10;

        //The text to be displayed
		msg = getParameter("text");

		//How many milliseconds between frames?
        str = getParameter("fps");
        try {
            if (str != null)
			{
                fps = Integer.parseInt(str);
            }
        } catch (Exception e) {}
        delay = (fps > 0) ? (1000 / fps) : 100;

        //Create Font and Color
		fnt = new Font("TimesRoman",Font.PLAIN,30);
		clr = new Color(255,0,0);
		spot_clr = new Color(0, 0, 255);
    }

    public void start()
	{
        //Start animating!
        if (animatorThread == null) {
            animatorThread = new Thread(this);
        }
        animatorThread.start();
    }

    public void stop()
	{
        //Stop the animating thread.
        animatorThread = null;
    }

    public void run()
	{
        //Just to be nice, lower this thread's priority
        //so it can't interfere with other processing going on.
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
 
        //Remember the starting time.
        long startTime = System.currentTimeMillis();

        //This is the animation loop.
        while (Thread.currentThread() == animatorThread)
		{
            //Display it.
            repaint();

            //Delay depending on how far we are behind.
            try {
                startTime += delay;
                Thread.sleep(Math.max(0, 
                                      startTime-System.currentTimeMillis()));
            } catch (InterruptedException e) {
                break;
            }
        }
    }

    public void paint(Graphics g)
	{
		FontMetrics fntM;
		int str_bk_size;

		g.setColor(clr);
		g.setFont(fnt);

		fntM = g.getFontMetrics();
		int font_height = fntM.getHeight();
		int x = size().width/2 - fntM.stringWidth(msg)/2;
		int y = size().height/2+font_height/2;

		g.drawString(msg, x, y);

		str_bk_size = fntM.stringWidth(" ");

		g.clipRect(x + strPt,0,str_bk_size,size().height);

		g.setColor(spot_clr);
		g.drawString(msg,x,y);

		strPt = (strPt + str_bk_size);
		if( strPt > fntM.stringWidth(msg) )  strPt = 0;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -