📄 example9_10.java
字号:
import java.awt.*;import java.awt.event.*;
public class Example9_10
{
public static void main(String args[])
{ new ThreadFrame();
}
}
class ThreadFrame extends Frame implements Runnable,ActionListener
{ TextField text1,text2;
boolean boo;
Label label=new Label("欢迎使用本字典");
Button fast=new Button("加速");
Thread Scrollwords=null;
ThreadFrame()
{ setLayout(new FlowLayout());
Scrollwords=new Thread(this);
text1=new TextField(10);
text2=new TextField(10);
add(text1);
add(text2);
add(fast);
add(label);
text1.addActionListener(this);
fast.addActionListener(this);
setBounds(100,100,400,280);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
}
);
Scrollwords.start();
}
public void run()
{ while(true)
{ int x=label.getBounds().x;
int y=120;
x=x+5;
label.setLocation(x,y);
if(x>380)
{x=10;
label.setLocation(x,y);}
try{ Scrollwords.sleep(100);
}
catch(InterruptedException e){}
if(boo)
{return;}
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==text1)
{if(text1.getText().equals("Boy"))
{text2.setText("男孩");}
else if(text1.getText().equals("die"))
{boo=true;}
else
{
text2.setText("没有该单词!");
}
}
if(e.getSource()==fast)
{Scrollwords.interrupt();}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -