当前位置: 代码迷 >> J2SE >> 关于生产者和消费者一个简单的有关问题
  详细解决方案

关于生产者和消费者一个简单的有关问题

热度:70   发布时间:2016-04-24 15:06:20.0
关于生产者和消费者一个简单的问题求助!
我写的程序编译和运行都没有报错,但是不知道为什么界面上没有显示预期结果,代码如下:
import   java.awt.*;
import   java.awt.event.*;
import   javax.swing.*;

public   class   MainFrame   extends   JFrame   implements   Runnable   {
JPanel   panel   =   new   JPanel(new   BorderLayout());

JPanel   panel1   =   new   JPanel(new   BorderLayout());

JPanel   panel11   =   new   JPanel();

JPanel   panel12   =   new   JPanel();

JPanel   panel13   =   new   JPanel();

JPanel   panel2   =   new   JPanel(new   FlowLayout(FlowLayout.LEFT));

JPanel   panel3   =   new   JPanel(new   BorderLayout());

JPanel   panel31   =   new   JPanel();

JPanel   panel32   =   new   JPanel();

JPanel   panel33   =   new   JPanel();

JLabel   label1   =   new   JLabel( "生产时间间隔: ");

JLabel   label2   =   new   JLabel( "容器大小: ");

JLabel   label3   =   new   JLabel( "消费时间间隔: ");

JTextField   textField1   =   new   JTextField(10);

JTextField   textField2   =   new   JTextField(10);

JTextField   textField3   =   new   JTextField(10);

JLabel[]   label;

JLabel   label11;

JButton   ProducerButton_start   =   new   JButton( "启动生产 ");

JButton   ProducerButton_suspend   =   new   JButton( "暂停生产 ");

JButton   ConsumerButton_start   =   new   JButton( "启动消费 ");

JButton   ConsumerButton_suspend   =   new   JButton( "暂停消费 ");

JLabel   label4   =   new   JLabel( "产品数量: ");

JLabel   label5   =   new   JLabel( "0 ");

Thread   producer_thread_start   =   new   Thread(this);

Thread   producer_thread_stop   =   new   Thread(this);

Thread   producer_thread_suspend   =   new   Thread(this);

Thread   producer_thread_resume   =   new   Thread(this);

Thread   consumer_thread_start   =   new   Thread(this);

Thread   consumer_thread_stop   =   new   Thread(this);

Thread   consumer_thread_suspend   =   new   Thread(this);

Thread   consumer_thread_resume   =   new   Thread(this);

int   s   =   0;

suspend_and_resume   sr1   =   new   suspend_and_resume();

suspend_and_resume   sr2   =   new   suspend_and_resume();

int   x_size,   y_size;

int   flag   =   0;

int   sum   =   0;

volatile   boolean   istrue1;

volatile   boolean   istrue2;

volatile   boolean   suspend_flag1   =   false;

volatile   boolean   suspend_flag2   =   false;

Object   obj1   =   new   Object();

Object   obj2   =   new   Object();

volatile   boolean   available1   =   false;

volatile   boolean   available2   =   false;
  相关解决方案