📄 extendwords.java
字号:
import java.awt.*;
import java.applet.*;
public class ExtendWords extends Applet implements Runnable
{
private Image myImage;
private Graphics myGraphic;
private int width = 0, height = 0;
private String myText, words;
private Thread mythread;
private int xPosition = 0, yPosition = 0, myHeight;
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;
myHeight = height / 3;
yPosition = myHeight;
myText = getParameter("words");
if(myText!=null)
words = myText;
myImage = createImage(width,height);
myGraphic = myImage.getGraphics();
}
public void start()
{
if(mythread == null)
{
mythread = new Thread(this);
mythread.start();
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
g.drawImage(myImage, 0, yPosition, width, myHeight ,this);
}
public void run()
{
try
{
while(true)
{
yPosition = 0;
myHeight = height;
myGraphic.setColor(Color.white);
myGraphic.fillRect(0 ,0, width, height);
repaint();
mythread.sleep(100);
if(times == 0)
{
myGraphic.setColor(Color.blue);
for(int i = width; i>=0; i--)
{
myGraphic.fillRect(i, height / 3 ,width, height /10);
repaint();
mythread.sleep(10);
}
}
else if(times == 1)
{
myGraphic.setColor(Color.yellow);
for(int i = 0; i<=width; i++)
{
myGraphic.fillRect(0, height / 3 ,i, height /10);
repaint();
mythread.sleep(10);
}
}
yPosition = height / 3;
myHeight = height / 3;
for(int i = height / 3; i>=0; i--)
{
xPosition = 0;
yPosition--;
myHeight = myHeight + 2;
if(times == 0)
{
myGraphic.setColor(Color.blue);
myGraphic.fillRect(0,0, width,height);
myGraphic.setFont(font);
myGraphic.setColor(Color.white);
myGraphic.drawString(words,10,35);
times++;
}
else if(times == 1)
{
myGraphic.setColor(Color.yellow);
myGraphic.fillRect(0,0, width,height);
myGraphic.setFont(font);
myGraphic.setColor(Color.black);
myGraphic.drawString(words,10,35);
times=0;
}
repaint();
mythread.sleep(100);
}
mythread.sleep(2500);
}
}
catch(InterruptedException e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -