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

📄 extendtext.java

📁 Java Applet实例编程.rar
💻 JAVA
字号:
import java.awt.*;
import java.applet.*;

public class ExtendText extends Applet implements Runnable
{
	private Image buffer;
	private Graphics gContext;
	private int width = 0, height = 0;
	private String param, words;
	private Thread thread;
	private int xpos = 0, ypos = 0, xw, xh;
	private int times = 0;
	private Font font;
	
	public void init()
	{
		font = new Font("TimesRoman", Font.BOLD,30);
		width = this.size().width;
		height = this.size().height;
		xw = width;
		xh = height / 3;
		ypos = xh;
		param = getParameter("words");
		if(param!=null)
			words = param;
		buffer = createImage(width,height);
		gContext = buffer.getGraphics();
	}  
  
	public void start()
	{
		if(thread == null)
		{
			thread = new Thread(this);
			thread.start();
		}
	}     
   
	public void update(Graphics g)
	{
		paint(g);
	}
   
	public void paint(Graphics g)
	{
		g.drawImage(buffer, 0, ypos, width, xh ,this); 
	}
   
	public void run()
	{
		int w, h, x, y;
		try
		{
			while(true)
			{
				ypos = 0;
				xh = height;
				gContext.setColor(Color.white);
				gContext.fillRect(0 ,0, width, height);
				repaint();
				thread.sleep(100);
				if(times == 0)
				{
					gContext.setColor(Color.blue);
					for(int i = width; i>=0; i--)
					{
						gContext.fillRect(i, height / 3 ,width, height /10); 
						repaint();
						thread.sleep(10);
					}
				}
				else if(times == 1)
				{
					gContext.setColor(Color.pink);
					for(int i = 0; i<=width; i++)
					{
						gContext.fillRect(0, height / 3 ,i, height /10);
						repaint();
						thread.sleep(10);
					}
				}
				ypos = height / 3;
				xh = height / 3;
				for(int i = height / 3; i>=0; i--)
				{
					xpos = 0;
					ypos--;
					xh = xh + 2;
					if(times == 0)
					{
						gContext.setColor(Color.blue);
						gContext.fillRect(0,0, width,height);
						gContext.setFont(font);
						gContext.setColor(Color.white); 
						gContext.drawString(words,0,35);  
						times++;
					}
					else if(times == 1)
					{
						gContext.setColor(Color.pink);
						gContext.fillRect(0,0, width,height);
						gContext.setFont(font);
						gContext.setColor(Color.black); 
						gContext.drawString(words,0,35);           
						times=0;
					}				
					repaint();
					thread.sleep(100);
				}
				thread.sleep(2500);           
			}
		}
		catch(InterruptedException e)
		{
		
		}
	}	
}

⌨️ 快捷键说明

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