Topic: 请各位帮我看一下程序

  Print this page

1.请各位帮我看一下程序 Copy to clipboard
Posted by: fictive
Posted on: 2005-11-08 19:33

我按照书的例子编了一个关于售票的小程序。可编译通过,但不能执行。各位高手能帮我看看错在哪吗?
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example_10 extends Applet implements Runnable
{
  Thread five,ten,twenty;
  int 五圆=2,十圆=0,二十圆=0;
  static TextArea text;
  String s=null;
  public void init()
  {
    five=new Thread(this);
    ten=new Thread(this);
    twenty=new Thread(this);
    text=new TextArea(15,20);
    add(text);
  }
  public void start()
  {
    
    twenty.start();
    ten.start();
    five.start();
    
    
  }
  
  public void run()
  {
    if(Thread.currentThread()==five)
     {
      
      
      售票规则(5);
      
     }
     else
     {
       if(Thread.currentThread()==ten)
       {
       
         
         售票规则(10);
       }  
    
     else
     {
        if(Thread.currentThread()==twenty)
        {
          
          
         售票规则(20);
         }
         
     }
     }
  }
   public synchronized void 售票规则(int money)
  {
    switch (money)
    {
  
     case 5:
     五圆+=1;
     s="您的钱正好,给你票";
     Example_9.text.append(s+"\n");
    
     break;
    
     case 10:
     while (五圆<1)
     {
       try
       {
         wait();
       }
       catch(InterruptedException e){}
     }
     五圆-=1;
     十圆+=1;
     s="找你五圆,给你票";
    
    
     Example_9.text.append(s+"\n");
    
     break;
    
     case 20:
     while(!((五圆>0)&&(十圆>0))&&(五圆<3))
     {
       try
       { wait();
       }
       catch(InterruptedException e){}
     }
     if(五圆<3)
     {
       十圆-=1;
       五圆-=1;
     }
     else
     {
       if (十圆<1)
        {
          五圆-=3;
        }
     }
     s="找你十五圆钱,你的票";
     Example_9.text.append(s+"\n");
    
     break;
    
    
     }
     notifyAll();
  }
}

2.Re:请各位帮我看一下程序 [Re: fictive] Copy to clipboard
Posted by: lfcjecboss
Posted on: 2005-11-09 08:54

应该是你没有引用example_09的包!

3.Re:请各位帮我看一下程序 [Re: fictive] Copy to clipboard
Posted by: fictive
Posted on: 2005-11-09 19:17

问题已解决,非常感谢楼上热心的朋友.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923