testthread4.java

来自「这是一张java应用教程的随书光盘」· Java 代码 · 共 36 行

JAVA
36
字号
import java.applet.*;import java.awt.*;
public class TestThread4 extends java.applet.Applet implements Runnable
{ int x=0,y=5; Thread Scrollwords=null;
  public void init()
  { setFont(new Font("TimesRoman",Font.BOLD,16));
  }
  public void start()
  {
  if(Scrollwords ==null)
      {Scrollwords =new Thread(this);
      Scrollwords .start();
      }
  }
 public void run ()
 {
  while(Scrollwords !=null)
    {x=x+1;y=y+1;
     if(x>200)
     x=0;
     if(y>100)
     y=10;;
     repaint();
     try{
        Scrollwords .sleep(20);
        } 
     catch(InterruptedException e){}
    }
 }
 public void paint(Graphics g)
 {g.drawString("Here is big club,welcome to all!",x,y);
 }
 public void stop()
   {Scrollwords.yield();
   Scrollwords =null;
   }
}

⌨️ 快捷键说明

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