📄 flyingwords.java
字号:
import java.awt.*;
import java.applet.*;
public class FlyingWords extends Applet implements Runnable{
private Image myImage;
private Graphics myGraphic;
private Font font;
private String myString;
private Thread mythread;
private int fontSize;
public void init(){
String myText;
myImage = createImage(getSize().width, getSize().height);
myGraphic = myImage.getGraphics();
myText = getParameter("text");
if(myText == null)
myString = "你好!";
else
myString = myText;
font = new Font("TimesRoman", Font.BOLD, 10);
}
public void start(){
if(mythread == null){
mythread = new Thread(this);
mythread.start();
}
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
myGraphic.setColor(Color.blue);
myGraphic.fillRect(0,0,getSize().width, getSize().height);
font = new Font("TimesRoman", Font.BOLD, fontSize);
myGraphic.setFont(font);
myGraphic.setColor(Color.red);
FontMetrics fm = myGraphic.getFontMetrics(font);
int fontHeight = fm.getHeight();
int w;
int baseLine = getSize().height / 2 + fontHeight / 2;
w = fm.stringWidth(myString);
w = (getSize().width - w) / 2;
myGraphic.drawString(myString, w, baseLine-=20);
g.drawImage(myImage,0,0, this);
fontSize++;
}
public void run(){
while(true){
repaint();
if(fontSize >getSize().height)
fontSize = 0;
try{
mythread.sleep(50);
}catch (InterruptedException e){}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -