资源描述:
《进程并发演示模型》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassCZFrameextendsJFrameimplementsActionListener{CZThreadthread1,thread2,thread3;JButtonwait1=newJButton("等待"),wait2=newJButton("等待"),wait3=newJButton("等待");JButtonexit=newJButton("退出");JLabelnam
2、e=newJLabel("作者:谢滨宇");publicCZFrame(intn1,intn2,intn3){setTitle("进程并发演示模型");setSize(500,550);setVisible(true);thread1=newCZThread(n1);thread2=newCZThread(n2);thread3=newCZThread(n3);Containercontainer=getContentPane();container.setLayout(null);container.add(thre
3、ad1.panel);container.add(thread2.panel);container.add(thread3.panel);wait1.setBounds(400,150,70,30);wait2.setBounds(400,250,70,30);wait3.setBounds(400,350,70,30);exit.setBounds(200,450,70,30);container.add(wait1);container.add(wait2);container.add(wait3);contain
4、er.add(exit);wait1.addActionListener(this);wait2.addActionListener(this);wait3.addActionListener(this);exit.addActionListener(this);JLabellabel=newJLabel("进程并发演示模型");Fontfont=newFont("宋体",Font.BOLD,16);label.setFont(font);label.setBounds(175,20,180,50);container
5、.add(label);name.setBounds(400,40,100,50);container.add(name);thread1.start();thread2.start();thread3.start();}publicvoidactionPerformed(ActionEvente){Objects=e.getSource();if(s==exit){/*thread1.suspend();thread2.suspend();thread3.suspend();*/inti=JOptionPane.sh
6、owConfirmDialog(null,"确认退出吗?","退出",JOptionPane.YES_NO_OPTION);if(i==0)System.exit(0);/*thread1.resume();thread2.resume();thread3.resume();*/}elseif(s==wait1){try{if(thread1.st==0){thread1.suspend();thread1.st=1;wait1.setText("执行");thread1.num--;}else{thread1.res
7、ume();thread1.st=0;wait1.setText("等待");thread1.num++;}}catch(Exceptione1){}}elseif(s==wait2){try{if(thread2.st==0){thread2.suspend();thread2.st=1;wait2.setText("执行");thread1.num--;}else{thread2.resume();thread2.st=0;wait2.setText("等待");thread1.num++;}}catch(Exce
8、ptione1){}}else{try{if(thread3.st==0){thread3.suspend();thread3.st=1;wait3.setText("执行");thread1.num--;}else{thread3.resume();thread3.st=0;wait3.setText("等待");thread1