操作系统课程设计多进程同步橘子苹果问题源代码.docx

上传人:b****1 文档编号:14126954 上传时间:2023-06-20 格式:DOCX 页数:47 大小:22.68KB
下载 相关 举报
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第1页
第1页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第2页
第2页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第3页
第3页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第4页
第4页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第5页
第5页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第6页
第6页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第7页
第7页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第8页
第8页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第9页
第9页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第10页
第10页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第11页
第11页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第12页
第12页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第13页
第13页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第14页
第14页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第15页
第15页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第16页
第16页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第17页
第17页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第18页
第18页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第19页
第19页 / 共47页
操作系统课程设计多进程同步橘子苹果问题源代码.docx_第20页
第20页 / 共47页
亲,该文档总共47页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

操作系统课程设计多进程同步橘子苹果问题源代码.docx

《操作系统课程设计多进程同步橘子苹果问题源代码.docx》由会员分享,可在线阅读,更多相关《操作系统课程设计多进程同步橘子苹果问题源代码.docx(47页珍藏版)》请在冰点文库上搜索。

操作系统课程设计多进程同步橘子苹果问题源代码.docx

操作系统课程设计多进程同步橘子苹果问题源代码

import;

import;

import;

import;

import;

import;

importjava.awt.*;

import;

import;

import;

importjavax.swing.*;

import;

publicclassApple

{

/**

*生成一个缓冲池类对应的对象叫myStorage,以后所有的生产者线程和消费者线程都对这个myStorage对象进行操作!

*/

staticMyStoragemyStorage=newMyStorage();

privateJFramewindow;

//该数组用来存取生产橘子和苹果的线程,分别20个

staticIncreaseapple[]appleincrease=newIncreaseapple[20];

staticIncreaseorange[]orangeincrease=newIncreaseorange[20];

//该数组用来存放消费者线程,最多20个

staticDecreaseapple[]appledecrease=newDecreaseapple[20];

staticDecreaseorange[]orangedecrease=newDecreaseorange[20];

//代表两个生产者对应线程的数目,i1为苹果,i2为橘子

staticinti1=0;

staticinti2=0;

//代表消费者对应线程的数目,d1为苹果,d2为橘子

staticintd1=0;

staticintd2=0;

staticTextAreatextArea1;

staticTextAreatextArea2;

staticJProgressBarprogressbar=newJProgressBar(0,20);

staticDrawdraw1;

staticJTextFieldt1;

staticJTextFieldt2;

staticJTextFieldt3;

staticJTextFieldt4;

publicvoidcreateMainWindow()

{

window=newJFrame("橘子苹果问题");

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

window.setSize(700,700);

window.setResizable(false);

JPanelpanel=newJPanel();

panel.setLayout(null);

JLabelApp1=newJLabel("生产苹果者数:

");

App1.setBounds(10,500,100,25);

panel.add(App1);

progressbar.setStringPainted(true);

progressbar.setBounds(200,640,300,30);

panel.add(progressbar);

progressp=newprogress(myStorage);

p.start();

draw1=newDraw(myStorage);

draw1.setBounds(0,0,700,300);

panel.add(draw1);

t1=newJTextField();

t1.setBounds(120,500,60,25);

t1.addKeyListener(newKeyAdapter()

{

publicvoidkeyTyped(KeyEventevent)

{

charch=event.getKeyChar();

if(ch<'0'||ch>'9')

{

event.consume();

}

}

});

panel.add(t1);

JButtoninapp1=newJButton("增加");

inapp1.setBounds(190,500,60,25);

panel.add(inapp1);

inapp1.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

if(i1<20)

{

increaseappleProducer();

t1.setText(String.valueOf(i1));

}

}

});

JButtondeapp1=newJButton("减少");

deapp1.setBounds(260,500,60,25);

panel.add(deapp1);

deapp1.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

if(i1>0)

{

decreaseappleProducer();

t1.setText(String.valueOf(i1));

}

}

});

JLabelOrg1=newJLabel("生产橘子者数:

");

Org1.setBounds(10,550,100,25);

panel.add(Org1);

t2=newJTextField();

t2.setBounds(120,550,60,25);

t2.addKeyListener(newKeyAdapter()

{

publicvoidkeyTyped(KeyEventevent)

{

charch=event.getKeyChar();

if(ch<'0'||ch>'9')

{

event.consume();

}

}

});

panel.add(t2);

JButtoninorg1=newJButton("增加");

inorg1.setBounds(190,550,60,25);

panel.add(inorg1);

inorg1.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

if(i2<20)

{

increaseorangeProducer();

t2.setText(String.valueOf(i2));

}

}

});

JButtondeorg1=newJButton("减少");

deorg1.setBounds(260,550,60,25);

panel.add(deorg1);

deorg1.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

if(i2>0)

{

decreaseorangeProducer();

t2.setText(String.valueOf(i2));

}

}

});

//**消费者的数目设置苹果核橘子*/

JLabelApp2=newJLabel("消费苹果者数:

");

App2.setBounds(330,500,100,25);

panel.add(App2);

t3=newJTextField();

t3.setBounds(440,500,60,25);

panel.add(t3);

JButtoninapp2=newJButton("增加");

inapp2.setBounds(510,500,60,25);

panel.add(inapp2);

inapp2.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

if(d1<20)

{

increaseappleConsumer();

t3.setText(String.valueOf(d1));

}

}

});

JButtondeapp2=newJButton("减少");

deapp2.setBounds(580,500,60,25);

panel.add(deapp2);

deapp2.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

if(d1>0)

{

decreaseappleConsumer();

t3.setText(String.valueOf(d1));

}

}

});

JLabelOrg2=newJLabel("消费橘子者数:

");

Org2.setBounds(330,550,100,25);

panel.add(Org2);

t4=newJTextField();

t4.setBounds(440,550,60,25);

panel.add(t4);

JButtoninorg2=newJButton("增加");

inorg2.setBounds(510,550,60,25);

panel.add(inorg2);

inorg2.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

if(d2<20)

{

increaseorangeConsumer();

t4.setText(String.valueOf(d2));

}

}

});

JButtondeorg2=newJButton("减少");

deorg2.setBounds(580,550,60,25);

panel.add(deorg2);

deorg2.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

if(d2>0)

{

decreaseorangeConsumer();

t4.setText(String.valueOf(d2));

}

}

});

/**

*这里的代码是实现了设计要求中的第三条:

生产者速度可调。

*/

JLabelappsp1=newJLabel("苹果生产速度:

");

appsp1.setBounds(10,400,100,25);

panel.add(appsp1);

finalJTextFieldtsp1=newJTextField();

tsp1.setBounds(120,400,60,25);

tsp1.setText(String.valueOf(Increaseapple.speed));

tsp1.addKeyListener(newKeyAdapter()

{

publicvoidkeyTyped(KeyEventevent)

{

charch=event.getKeyChar();

if(ch<'0'||ch>'9')

{

event.consume();

}

}

});

panel.add(tsp1);

JButtonappalter1=newJButton("修改");

appalter1.setBounds(190,400,60,25);

panel.add(appalter1);

//在这里实现了控制生产速度的功能

appalter1.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

Stringstr1=tsp1.getText();

longi=Long.parseLong(str1);

if(i<=10000&&i>=0)

{

Increaseapple.speed=i;

}

elseif(i<0)

{

Increaseapple.speed=0;

tsp1.setText(String.valueOf(Increaseapple.speed));

}

else

{

Increaseapple.speed=10000;

tsp1.setText(String.valueOf(Increaseapple.speed));

}

}

});

/**

*这里的代码是实现了设计要求中的第三条:

生产者速度可调。

*/

JLabelorgsp1=newJLabel("橘子生产速度:

");

orgsp1.setBounds(10,450,100,25);

panel.add(orgsp1);

finalJTextFieldtsp2=newJTextField();

tsp2.setBounds(120,450,60,25);

tsp2.setText(String.valueOf(Increaseapple.speed));

tsp2.addKeyListener(newKeyAdapter()

{

publicvoidkeyTyped(KeyEventevent)

{

charch=event.getKeyChar();

if(ch<'0'||ch>'9')

{

event.consume();

}

}

});

panel.add(tsp2);

JButtonorgalter1=newJButton("修改");

orgalter1.setBounds(190,450,60,25);

panel.add(orgalter1);

//在这里实现了控制生产速度的功能

orgalter1.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

Stringstr1=tsp2.getText();

longi=Long.parseLong(str1);

if(i<=10000&&i>=0)

{

Increaseapple.speed=i;

}

elseif(i<0)

{

Increaseapple.speed=0;

tsp2.setText(String.valueOf(Increaseorange.speed));

}

else

{

Increaseapple.speed=10000;

tsp2.setText(String.valueOf(Increaseorange.speed));

}

}

});

/**

*这里的代码是实现了设计要求中的第三条:

消费者速度可调。

*/

JLabelappsp2=newJLabel("苹果消费速度");

appsp2.setBounds(260,400,100,25);

panel.add(appsp2);

finalJTextFieldtsp3=newJTextField();

tsp3.setBounds(370,400,60,25);

tsp3.setText(String.valueOf(Decreaseapple.speed));

tsp3.addKeyListener(newKeyAdapter()

{

publicvoidkeyTyped(KeyEventevent)

{

charch=event.getKeyChar();

if(ch<'0'||ch>'9')

{

event.consume();

}

}

});

panel.add(tsp3);

JButtonappalter2=newJButton("修改");

appalter2.setBounds(440,400,60,25);

panel.add(appalter2);

//这里实现了控制消费速度的功能

appalter2.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

Stringstr2=tsp3.getText();

longi=Long.parseLong(str2);

if(i<=10000&&i>=0)

{

Decreaseapple.speed=i;

}

elseif(i<0)

{

Decreaseapple.speed=0;

tsp3.setText(String.valueOf(Decreaseapple.speed));

}

else

{

Decreaseapple.speed=10000;

tsp3.setText(String.valueOf(Decreaseapple.speed));

}

}

});

JLabelorgsp2=newJLabel("橘子消费速度");

orgsp2.setBounds(260,450,100,25);

panel.add(orgsp2);

finalJTextFieldtsp4=newJTextField();

tsp4.setBounds(370,450,60,25);

tsp4.setText(String.valueOf(Decreaseapple.speed));

tsp4.addKeyListener(newKeyAdapter()

{

publicvoidkeyTyped(KeyEventevent)

{

charch=event.getKeyChar();

if(ch<'0'||ch>'9')

{

event.consume();

}

}

});

panel.add(tsp4);

JButtonorgalter2=newJButton("修改");

orgalter2.setBounds(440,450,60,25);

panel.add(orgalter2);

orgalter2.addActionListener(newActionListener()

{

@Override

publicvoidactionPerformed(ActionEvente)

{

Stringstr2=tsp4.getText();

longi=Long.parseLong(str2);

if(i<=10000&&i>=0)

{

Decreaseorange.speed=i;

}

elseif(i<0)

{

Decreaseorange.speed=0;

tsp4.setText(String.valueOf(Decreaseorange.speed));

}

else

{

Decreaseorange.speed=10000;

tsp4.setText(String.valueOf(Decreaseorange.speed));

}

}

});

/**

*这里构造了能够实现第五条要求的组件,可以显示当前线程的状态,实现了设计要求中的第五条。

*/

textArea2

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2