这个怎么运行不出来结果?

来源:互联网 发布:vue.js vm是什么意思 编辑:程序博客网 时间:2024/05/02 04:20

//左手画圆,右手画方!

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Examplelf extends Applet implements Runnable
{
 Thread left,right;
 Graphics mypen;
 int x,y;
 public void init ()
 {
  left=new Thread (this);
  right=new Thread (this);
  x=10;y=10;
  mypen=getGraphics ();
 }
 public void start ()
 {
  left.start ();
  right.start ();
  
 }
 public void  run ()
 {
  while (true)
  {
   if(Thread.currentThread ()==left)
   {
    x=x+1;
    if (x>20) x=10;
    mypen.setColor (Color.blue);
    mypen.clearRect (10,10,300,40);
    mypen.drawRect (10+x,10,40,40);
    try{
     left.sleep (60);
    }
    catch (InterruptedException e) {}
    
    }
    else if (Thread.currentThread ()==right)
    {
     y=y+1;
     if (y>240) y=10;
     mypen.setColor (Color.red);
    mypen.clearRect (10,90,300,40);
    mypen.drawOval (10+y,90,40,40);
    try{
     right.sleep (60);
     }
        catch (InterruptedException e)  {}
      }
      }
    }
}
 

原创粉丝点击