📄 jumptext.java
字号:
//程序2.1跳动的文字
import java.awt.*;
public class JumpText extends java.applet.Applet implements Runnable
{
char separated[];
String s=null;
Thread killme=null;
int i;
int x_coord=0,y_coord=0;
String num;
int speed=35;
int counter=0;
boolean threadSuspended=false;//设置线程未挂起标志
public void init()
{
//从HTML文件中读入或者选用默认内容作为要显示的文字
s=getParameter("text");//
if(s==null)
s="Hello";
separated=new char[s.length()];
s.getChars(0,s.length(),separated,0); //将s中字符拷贝到separated中
resize(150,50);
setFont(new Font("TimesRoman",Font.BOLD,36)); //设置字体
}
public void start()
{
if(killme==null)
{
killme=new Thread(this);// 创建线程
killme.start(); //线程开始运行
}
}
public void stop(){
killme=null; //停止线程
}
public void run()
{
while(killme!=null)
{
try{Thread.sleep(100);}
catch(InterruptedException e) {}
repaint();
}
killme=null;
}
public void paint(Graphics g)
{
for(i=0;i<s.length();i++)
{ //随机的选择文字显示的位置
x_coord=(int)(Math.random()*10+15*i);
y_coord=(int)(Math.random()*10+36);
g.setColor(Color.blue);
g.drawChars(separated,i,1,x_coord,y_coord);
}
}
//处理鼠标按下的消息
//鼠标按下,线程挂起,再按下,线程继续运行
public boolean mouseDown(java.awt.Event evt,int x,int y)
{
if(threadSuspended)
killme.resume();
else
killme.suspend();
threadSuspended=!threadSuspended;
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -