import java.awt.event.*;
import java.awt.*;
import javax.swing.*;public class MaiPiao
{
public static void main(String[] args){
new WindowSell();
}
}
class WindowSell extends JFrame implements ActionListener
{
 static JTextArea text;
  JButton button;
  Thread Zhang;
  Thread Li;
  Thread Zhao;
  SellTicket sellticket;
  String name;
  public WindowSell(){
  sellticket=new SellTicket();
  text=new JTextArea(200,300);
  button=new JButton("开始买票");
  button.addActionListener(this);
  Zhang=new Thread();
  Zhang.setName("张三");
  Li=new Thread();
  Li.setName("李四");
  Zhao=new Thread();
  Zhao.setName("赵六");
  
  this.add(button,new BorderLayout().NORTH);
  this.add(text,new BorderLayout().SOUTH);
  setVisible(true);
  setSize(200,150);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setTitle("售票系统");
  }
  public void  actionPerformed(ActionEvent e){
     try{
    Zhang.start();
Li.start();
Zhao.start();
  }  catch(Exception ee){}
  }
  public void run(){
   name=Thread.currentThread().getName();
  if(name=="张三"){
     sellticket.售票规则(20);
    }else if(name=="李四"){
 sellticket.售票规则(10);
}else if(name=="赵六"){
 sellticket.售票规则(5);
 }
  }class SellTicket
{
//SellTicket sellticket;
String s;
int n;
int FiveYuan=3,TenYuan=0,TwentyYuan=0;
public synchronized void 售票规则(int money){
//String name2=Thread.currentThread().getName();
if(n==20){
while(FiveYuan<3){
 try{ s="没有足够零钱,请暂时等待……";
 WindowSell.text.append("\n"+s);
  wait();
 }catch(Exception epe){}
    }
     WindowSell.text.append("\n"+"给"+name+"一张票,并找15元。");
FiveYuan=FiveYuan-3;
TwentyYuan=TwentyYuan+1;
  }else if(n==10){
  while(FiveYuan<1){
 try{ s="没有足够零钱,请暂时等待……";
    WindowSell.text.append("\n"+s);
      wait();
 }catch(Exception exe){}
    }
WindowSell.text.append("\n"+"给"+name+"一张票,并找5元。");
FiveYuan=FiveYuan-1;
TenYuan=TenYuan+1;
  }else if(n==5){
  FiveYuan=FiveYuan+1;
  WindowSell.text.append("\n"+"给"+name+"一张票");
  }
       notifyAll();
 }
   }

}
麻烦各位大虾看下,这个小程序问题出在哪里?编译没错误,能运行,但是,点button没有反应..

解决方案 »

  1.   

    button.addActionListener(this)
    这句··你的按钮添加的监听我没看见在哪里啊··
      

  2.   

    也就是说你的监听里貌似没写run()方法··你的下面的run()是想写在监听里的吗?怎么写到外面去了··
      

  3.   

    “/”应用程序中的服务器错误。
    --------------------------------------------------------------------------------远程处理配置失败,异常为“System.Runtime.Remoting.RemotingException: 信道“channel01”已注册。
      在 System.Runtime.Remoting.Channels.ChannelServices.RegisterChannelInternal(IChannel chnl, Boolean ensureSecurity)
      在 System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(IChannel chnl, Boolean ensureSecurity)
      在 System.Runtime.Remoting.RemotingConfigHandler.ConfigureChannels(RemotingXmlConfigFileData configData, Boolean ensureSecurity)
      在 System.Runtime.Remoting.RemotingConfigHandler.ConfigureRemoting(RemotingXmlConfigFileData configData, Boolean ensureSecurity)”。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Runtime.Remoting.RemotingException: 远程处理配置失败,异常为“System.Runtime.Remoting.RemotingException: 信道“channel01”已注册。
      在 System.Runtime.Remoting.Channels.ChannelServices.RegisterChannelInternal(IChannel chnl, Boolean ensureSecurity)
      在 System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(IChannel chnl, Boolean ensureSecurity)
      在 System.Runtime.Remoting.RemotingConfigHandler.ConfigureChannels(RemotingXmlConfigFileData configData, Boolean ensureSecurity)
      在 System.Runtime.Remoting.RemotingConfigHandler.ConfigureRemoting(RemotingXmlConfigFileData configData, Boolean ensureSecurity)”。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  堆栈跟踪: 
    [RemotingException: 远程处理配置失败,异常为“System.Runtime.Remoting.RemotingException: 信道“channel01”已注册。
       在 System.Runtime.Remoting.Channels.ChannelServices.RegisterChannelInternal(IChannel chnl, Boolean ensureSecurity)
       在 System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(IChannel chnl, Boolean ensureSecurity)
       在 System.Runtime.Remoting.RemotingConfigHandler.ConfigureChannels(RemotingXmlConfigFileData configData, Boolean ensureSecurity)
       在 System.Runtime.Remoting.RemotingConfigHandler.ConfigureRemoting(RemotingXmlConfigFileData configData, Boolean ensureSecurity)”。]
       System.Runtime.Remoting.RemotingConfigHandler.ConfigureRemoting(RemotingXmlConfigFileData configData, Boolean ensureSecurity) +439
       System.Runtime.Remoting.RemotingConfigHandler.DoConfiguration(String filename, Boolean ensureSecurity) +39
       System.Runtime.Remoting.RemotingConfiguration.Configure(String filename, Boolean ensureSecurity) +42
       CSDN.Community.TopicFileDataCenter.TopicFileDataCenterEntry.GetT5TFC() +165
       CSDN.Community.TopicFileDataCenter.TopicFileDataCenterEntry.get_t5Tfc() +25
       CSDN.Community.TopicFileDataCenter.TopicFileDataCenterEntry.T5Reply(Guid topicId, DateTime createDate, ConfigInfo smallForum, ReplyInfo reply, CommunityUser user, UserSectionProfile usp, Int32 topicReplyCount, Int32 topicViewCount) +16
       CSDN.Community.PointForum.Services.ReplyTopicManager.ReplyTopic(ReplyInfo reply, DateTime& topicPostDate, String& errorInfo, CommunityUser user, UserSectionProfile usp, String& currReplyPageTopic) +1412
       CSDN.Community.WebSite.PointForum.Forum.ReplyT.bt_Submit_Click(Object sender, EventArgs e) +725
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 
      

  4.   

    没注释,看了一半,没耐心看下去,给一个经典教材你吧。看完应该会有一定的启发的。http://www.itqun.net/content-detail/242071.html
      

  5.   

    if(name=="张三"){
    这个你是不是应该这样写:
    if(name.equals("张三")){
      

  6.   

    嗯,我修改了一些地方的错误,包括在SellTicket类加上Runnable接口,并把run()方法放到SellTicket类里,试着运行了一下,修改了一下,但是还是不行
      

  7.   

    嗯,谢谢,呵呵,我修改过来了,我还试着修改了其它一些错误,但是还是没有找到主要错误,点击button还是不行。。
    写得匆忙,没有写注释,请原谅。。
      

  8.   

    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;public class MaiPiao
    {
    public static void main(String[] args){
    new WindowSell();
    }
    }class WindowSell extends JFrame implements ActionListener
    {
    //创建一个类继承JFrame类并添加ActionLiatener接口
     static JTextArea text;
      JButton button;
      Thread Zhang;//创建线程Zhang
      Thread Li;
      Thread Zhao;
      SellTicket sellticket;
      String name;
      public WindowSell(){
      sellticket=new SellTicket();
      text=new JTextArea(200,300);
      button=new JButton("开始买票");
      button.addActionListener(this);
      Zhang=new Thread();
      Zhang.setName("张三");
      Li=new Thread();
      Li.setName("李四");
      Zhao=new Thread();
      Zhao.setName("赵六");
      
      this.add(button,new BorderLayout().NORTH);
      this.add(text,new BorderLayout().SOUTH);
      setVisible(true);
      setSize(200,150);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setTitle("售票系统");
      }
    //ActionListener接口内方法的实现
      public void  actionPerformed(ActionEvent e){
         try{
        Zhang.start();
    Li.start();
    Zhao.start();
      }  catch(Exception ee){}
      }
    }    
    //创建SellTicket类并添加Runnable接口
    class SellTicket implements Runnable
    {
    SellTicket sellticket;
    String s,name;
    int n;
    int FiveYuan=3,TenYuan=0,TwentyYuan=0;
    //run()方法开始
      public void run(){
     name=Thread.currentThread().getName();
      if(name.equals("张三")){
         sellticket.售票规则(20);
        }else if(name.equals("李四")){
     sellticket.售票规则(10);
    }else if(name.equals("赵六")){
     sellticket.售票规则(5);
      }
        } public synchronized void 售票规则(int money){
    //售票方法
    if(money==20){
    while(FiveYuan<3){
     try{ s="没有足够零钱,请暂时等待……";
     WindowSell.text.append("\n"+s);
      wait();//如果使用该方法的线程传递的参数是20则须等待
     }catch(Exception epe){}
        }
         WindowSell.text.append("\n"+"给"+name+"一张票,并找15元。");
    FiveYuan=FiveYuan-3;
    TwentyYuan=TwentyYuan+1;
      }else if(money==10){
      while(FiveYuan<1){
     try{ s="没有足够零钱,请暂时等待……";
        WindowSell.text.append("\n"+s);
          wait();//如果使用该方法的线程传递的参数是10则须等待
     }catch(Exception exe){}
        }
    WindowSell.text.append("\n"+"给"+name+"一张票,并找5元。");
    FiveYuan=FiveYuan-1;
    TenYuan=TenYuan+1;
      }else if(money==5){
      FiveYuan=FiveYuan+1;
      WindowSell.text.append("\n"+"给"+name+"一张票");
      }
           notifyAll();//通知所有线程结束等待
     }
       }

    修改后还是老问题。