Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请各位帮我看一下程序
fictive





发贴: 3
积分: 0
于 2005-11-08 19:33 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我按照书的例子编了一个关于售票的小程序。可编译通过,但不能执行。各位高手能帮我看看错在哪吗?
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();
  }
}




话题树型展开
人气 标题 作者 字数 发贴时间
4469 请各位帮我看一下程序 fictive 4724 2005-11-08 19:33
3436 Re:请各位帮我看一下程序 lfcjecboss 21 2005-11-09 08:54
3454 Re:请各位帮我看一下程序 fictive 18 2005-11-09 19:17

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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